Being Awesome with Javascript and Jquery A tutorial

Being Awesome with Javascript and Jquery A tutorial by Zoe F

Tutorial http: //www. binaryspark. com/classes/Javascript_rocks/javascript_lab_instructions. html goo. gl/m 7 fa 4 t

<Html> <head> <script> I am some header 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> </body> </html>

Variables • Strings: – var a = "I am a string"; – var b = “So am I!”; – var c = “ 100”; • Numbers: – var num 1 = 100; – var whatsup = 100. 10; – var num 3 = 0. 10; • Booleans – var okay 1 = true; – var I_fail = false; • More exotic variables: Objects, arrays, functions. . .

Do some stuff with variables! Put two strings together! var first. Number = “five”; var second. Number = “ten”; var third. Number = firstnumber+secondnumber; //outputs: fiveten Put two variables together!! var first. Number = 5; var second. Number = 10; var third. Number = first. Number+second. Number; //outputs: 15

Comparisions var foo = 1; var bar = 0; var bim = 2; var whatsup = “ 1”; foo == bar; // console would output false foo != bar; // true foo > bim; // false foo <= bim; //true foo == whatsup; //false

Boolean Logic var foo = true; var bar = false; // OR statement returns 1, which is true foo || bar; // AND statement returns 0, which is false foo && bar; //If foo is true and bar is true

If/Thens if (thing you want to evaluate to true or false) { // The code in here will run if its true. } else { // this code 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" ); }

Functions Function buy. Oranges() { Find some oranges Bring them to me }; Function buy. Oranges(amount, max. Cost) { Find some oranges Choose amountof them If they are less than max. Cost, bring them to me }; buy. Oranges(5, 20); //Buy me 5 oranges if it’s less than $20

Jquery: It’s just another bunch of functions Reference: http: //www. w 3 schools. com/jquery/default. asp
- Slides: 11