Loops & Arrays & Functions- Lets do this, some more. :| /////////////////// /////////Loops ///////////////// For loops for( initialization; condition; increment step) Example for(var i = 15; i < 48; i = i + 1.1) OR for(var i=0; i < 10; i++) for(var i = 10; i >= 0; i--) While the loop runs the loop variable changes and repeats the code. /////////// While loops Essentially an if statement that loops. while(condition){ //Executes if condition is true //If condition neer becomes false, loop destroys you all! } IT check the condition first, then decides to run or not. Do While loops Will do the loop code, condition or no condition, then check Will run at least once. Arrays! Is a list of variables Declaration: var lister = [] Usage: lister[0] = "Whos" lister[1] = "on" lister.push("first"); Push just adds to the end, using specific index numbers (0,1, 2 etc) puts data in specific spots. Use a for loop to access the entire array. var groc = [] groc[0] = 'eggs' 0 -> eggs groc[1] = 'milk' 1 -> milk groc[2] = 'other stuff' 2 -> other stuff groc[4] = 'bread' 3 -> whatever black holes are made of 4 -> bread groc[1] = 'not milk' groc.push("eggs"); 0-> eggs groc.push("milk"); 1-> milk groc.push("other stuff"); 2-> other stuff groc.push("bread"); 3-> bread groc.push("bread"); 4-> bread groc[3] = "" use splice groc.splice(3,1) Splice Usage array.splice(index, howMany); Another useful thing. .length groc.length for(var i=0; i < groc.length; i++){ buy(groc[i]); } ///////////////////// /////// FUNCTIONS /////////////////// Definition: function is a mini program inside the big program. Functions can take in input, or not. Functions can output a result, or not. Example, no inputs, no outputs function digHole(){ universe.push("hole"); } Worker, needed no information to work, and gave no report that job was done. Upgrade, location required Parameters= x and y function digHole(x,y) universe[x][y] = "hole" } Upgrade, how did it go? function digHole(x,y){ var howDidItGo = "no idea"; if(universe[x][y] == "diamond") howDidItGo = "poorly" else howDidItGo = "Super Easy" return howDidItGo; } usage: var grandPlan = digHole(mx,my) alert(grandPlan) Lots of variables? Local VS Global Local are variables declared inside of smaller functions howDidItGo is a local variable Global are variable that are accessible by all functions, like mx & my function print(message){ papers.push(message); } print(); var gPapers = []; var crap = []; function getPapers(specific){ var p; //A local variable, so you can have multiple getPapers running at the same time. //This part chooses the value to send back, in this case an entire array if(specific == "Good kind") p = gPapers else p = crap //Take the value and send it along return p } var evilPlan = getPapers("Good kind"); var incinerator = getPapers("stuf"); trash(incinerator) /trash is some other made up function, just to show the super usage of getPapers;