You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var micky_mouse = {
"first_name": "Micky",
"last_name": "Mouse",
"address": "Disneyland"
}
var micky = {
"first_name": "Micky",
"last_name": "Mouse",
"address": "Disneyland"
}
// ##### JS Object Literals are reference types
// Access a literal value with ".key" syntax!
console.log(micky_mouse.first_name);
// This also works
console.log(micky_mouse["first_name"]);
console.log("Are JS Object Literals values? ")
if(micky_mouse === micky ) {
console.log(true );
} else {
console.log(false );
}
Conditional (if-else)
console.log("if - else if - else:")
// var state = "red";
var state = "green";
// var state = "blue";
// "message" is an example of a JavaScript Object Literal.
var message = {
"failing": "Tests are failing.",
"passing": "Tests are passing.",
"refactor": "Time to refactor."
}
if (state === "red") {
console.log(message.failing);
} else if (state === "green") {
console.log(message.passing);
} else { // Time to refactor.
console.log(message.refactor);
}
While loop
var a = [1,2,3,4];
var b = [1,2,3,4];
console.log("While Loop:")
var i = 0;
while(i < a.length){
console.log("The element at index " + i + " is: " + a[i]);
i++;
}
For loop
var mixed = [1, "two", "three", true];
console.log("For Loop:")
// Most common mistake is using commas instead of "semicolons" inside the loop declaration.
for(var i = 0; i < mixed.length; i++) {
console.log("The element at index " + i + " is: " + mixed[i]);
}
Switch Case
var expression = "label2"
switch (expression) {
case "label1":
console.log("First case: label1");
break;
case "label2":
console.log("Second case: label2");
break;
case "labelN":
console.log("Nth case: labelN");
break;
default:
console.log("Default case.");
break;
}
Exercise: Implement a routine that checks to see if two arrays are identical.
Set "result" to "true" if the two arrays are equal, and to "false" if the two arrays are unequal.
Afternoon Lab:
Turn array compare exercise into a function that returns true or false.