Introduction to JavaScript Spring 2011 Class 5
esse quam videri
Arrays
var myArray = [myObject, myObject2, myObject3]; myArray.push(42, "hi there!");
console.log(myArray); console.log(myArray[1]); console.log(myArray[4]);
Loops
var i=0; while (i<=5){ console.log("The number is " + i + "\n"); i++; }
do{ console.log("The number is " + i + "\n"); i++; } while (i<=5);
for (i=0;i<=5;i++){ console.log("The number is " + i + "\n"); }
for (i=0;i<myArray.length;i++){ console.log("This array slot holds: " + myArray[i]); }
In Class Work #1
Make a html file with embedded or external javascript. Use examples of the following in your javascript:
- variables
- functions
- at least 1 conditional statement
- at least 1 object
For extra credit
- write output as markup on the page instead of console output
- take input from form fileds