learning javascript

6
Learning Javascript 1. Confirm and promptWe can make pop-up boxes appear! confirm("I am ok");prompt("Are you ok?"); 2. Data typesa. numbers (e.g. 4.3, 134)b. strings (e.g. "dogs go woof!", "JavaScript expert")c. booleans (e.g. false, 5 > 4) 3. ConditionalsIf the first condition is met, execute the first code block. If it is not met, execute the code in the else block. See the code on the right for another example. Conclusion: Part 1 Let's do a quick review! Data typesa. numbers - just use them like regular numbersb. strings - anything between a " " is a string. Words have to be strings.c. booleans - can only be true or false. VariablesWe store data values in variables. We can bring back the values of these variables by typing the variable name. Manipulating numbers & stringsa. numbers - comparison operators, modulob. strings - length, substring

Upload: faris

Post on 07-Sep-2015

215 views

Category:

Documents


0 download

DESCRIPTION

Some notes about Javascript

TRANSCRIPT

Learning Javascript1. Confirm and promptWe can make pop-up boxes appear! confirm("I am ok");prompt("Are you ok?");2. Data typesa. numbers (e.g. 4.3, 134)b. strings (e.g. "dogs go woof!", "JavaScript expert")c. booleans (e.g. false, 5 > 4)3. ConditionalsIf the first condition is met, execute the first code block. If it is not met, execute the code in the else block. See the code on the right for another example.

Conclusion: Part 1Let's do a quick review!Data typesa. numbers - just use them like regular numbersb. strings - anything between a " " is a string. Words have to be strings.c. booleans - can only be true or false.VariablesWe store data values in variables. We can bring back the values of these variables by typing the variable name.Manipulating numbers & stringsa. numbers - comparison operators, modulob. strings - length, substringconsole.log( ) Prints into the console whatever we put in the parentheses.

Some Javascript:

// Check if the user is ready to play!

confirm("Ready to Play? Bitch?");var age = prompt("Your age, Sir or Madam?");if(age 8){ console.log("This is just the beginning of my game empire. Stay tuned for more!");}else console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");

Functions:// This is what a function looks like:

var divideByThree = function (number) { var val = number / 3; console.log(val);};

var greeting = function (name) { console.log("Great to see you," + " " + name);};

/*jshint multistr:true */var text = "So this other day Faris ate a burger";var myName = "Faris";var hits = [];for (var i = 0;i