110 likes | 215 Views
Being Awesome with Javascript and Jquery. A tutorial by Zoe F. <Html> <head> <script> I am some inline javascript </script> <script src =I am a link to an external javascript file.js> </head> <body> <a href = I am some built-in javascript >Text</a> </html.
E N D
Being Awesome with Javascript and Jquery A tutorial by Zoe F
<Html> <head> <script> I am some inline javascript </script> <script src=I am a link to an external javascript file.js> </head> <body> <a href = I am some built-in javascript>Text</a> </html
Variables • Strings: • var a = "I am a string"; • var b = 'So am I!'; • Numbers: • var num1 = 100; • var num2 = 100.10; • var num3 = 0.10; • Booleans • var okay = true; • var fail = false; • Objects, arrays, functions
Comparisions var foo = 1; var bar = 0; varbim = 2; foo == bar; // console would output false foo != bar; // true foo >bim; // false foo <= bim;//true
Boolean Logic var foo = 1; var bar = 0; // returns 1, which is true foo || bar; // returns 0, which is false foo && bar;
If/Thens if (thing you want to evaluate to true or false) { // The code in here will run. } else { // the code in here will run if the above is false. }
An easier if/then statement: Switch switch ( foo ) { case "bar": alert( "the value was bar -- yay!" ); break; case "baz": alert( “It was baz:(" ); break; default: alert( “It wasnt either of those" ); }
For loops for ( [initialization]; [conditional]; [iteration] ) { [loopBody] } for ( vari = 0; i < 5; i++ ) { // Logs "try 0", "try 1", ..., "try 4". console.log( "try " + i); }
while ( [conditional] ) { [loopBody] } vari = -1; while ( ++i < 100 ) { //this is the same as writing “while ((i=i+1)<100)” // This block will be executed 100 times. console.log( "Currently at " + i ); }
Functions Function buyOranges() { Find some oranges Bring them to me }; Function buyOranges(amount, maxCost) { Find some oranges Choose amountof them If they are less than maxCost, bring them to me }; buyOranges(5, 20); //Buy me 5 oranges if it’s less than $20
Jquery:It’s just another bunch of functions Reference: http://www.w3schools.com/jquery/default.asp