JavaScript

[|crunchzilla.com] http://www.codecademy.com/courses/getting-started-v2/1#!/exercises/4

Write a string with at least 3 words and find the length of the string. Length counts every character in the string—including spaces! To check the length of something, we type "string" . length. Remember a string might not always be a word—you can put almost any character in between quotes to make a string.
 * 5. Data Types I & II: Numbers and Strings**

"Poly Prep School".length;

Write code that will evaluate true if I 'm coding like a champ! has more than 10 characters. You can just write the condition into your editor and it will be evaluated for you. You can use "string".length to find the number of characters in your string.
 * 6. Data Types III: Booleans**

"I am coding like a champ".length > 10;


 * 2. Comparisons**

console.log(15 > 4); console.log("Xiao Hui".length < 122); console.log("Goody Donaldson".length > 8); console.log(8*2 === 16); console.log(2*2 > 9) console.log(2*4 > 9)

if ( 100 > 2 ) { console.log("You are good at math!"); }
 * 3. Decisions, decisions**

console.log("Just letting you know: your program got to line 6");

if (5<3) { alert("Let's go down the first road!"); } else { console.log("hi there!"); }
 * 4. Computers are smart**


 * 5. More practice with conditionals**

if (5<3) { alert("I am right!"); } else { console.log("I am wrong!"); }


 * 6. Computers aren't smart**

if (10 === 10) { console.log("You got a true!"); } else { console.log("You got a false!"); }

Playing with strings and numbers

 * 1. Mid-lesson breather**

if(12 / 4 === "Ari".length){ confirm("Will this run the first block?"); } else { confirm("Or the second block?"); }

if ("Jon".length * 2 / (2+1) === 2 )
 * 2. Math**

{ console.log("The answer makes sense!"); } else { console.log("Error Error Error"); }


 * 3. Modulo**

console.log(14 % 3); console.log(99 % 8); console.log(11 % 3);


 * 4. Modulo and if/else**

if(6 % 4 ) { console.log("The first number is even!"); } else { console.log("The first number is odd!"); }

//Remember to not use quotes, or your age will turn into a string.// var myAge = 19; console.log(myAge);
 * http://www.codecademy.com/courses/getting-started-v2/4#!/exercises/0**
 * 1.Variables**


 * 2. More Variable Practice**

var myCountry = "USA"; console.log(myCountry); console.log(myCountry.substring(0,3));

//To print out the myName variable, put myName between the parentheses after console.log.//
 * 3. Change Variable Values**

var myName = "Dr. Bentz"; console.log(myName); myName = "Dr"; console.log(myName);

var myJob = "Teacher"; console.log(myJob.length);
 * 4. Conclusion Part 1**

There are three steps to an if / else statement. 1. Work out what condition you want 2. If the condition is true, work out what code you want to run. 3. If it is false, work out the other code you want to run!
 * 5. Conclusion Part 2**

Program your first game!
confirm("are you ready to play?");
 * 1. Confirm**

confirm("are you ready to play?"); var age = prompt("how old are you?");
 * 2. Old enough to play?**

if (age < 18) { console.log("You are allowed to play, but we are not taking any responsibility!"); } else { console.log("please play!"); }


 * 3. Storyline**
 * Delete previous code**

console.log("Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him."); console.log("Batman glares at you"); var userAnswer = prompt("Are you feeling lucky, punk?");
 * 4. First Move**

console.log("Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him."); console.log("Batman glares at you"); var userAnswer = prompt("Are you feeling lucky, punk?"); if (userAnswer === "yes") { console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!"); } else { console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman."); }
 * 5. The story heats up**

var feedback = prompt("please rate the game"); if (feedback > 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!"); }
 * 6. Asking the feedback**