This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fruit = "Apple"; | |
switch(fruit) { | |
case "Banana": | |
console.log("Loads of K"); | |
break; | |
case "Orange": | |
console.log("Zesty"); | |
break; | |
case "Apple": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const age = 21; | |
switch(age) { | |
case 0: | |
console.log("You cannot drink or drive"); | |
break; | |
case 1: | |
console.log("You cannot drink or drive"); | |
break; | |
case 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const age = 21; | |
// If someone is less than 16 | |
if(age < 16) { | |
console.log("You cannot drink or drive"); | |
} | |
// If someone is less than 19 but greater than 16 | |
else if(age < 19) { | |
console.log("You cannot drink but you can drive"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 1; | |
var b = 2; | |
// Addition Operator | |
console.log(a + b); | |
// Subtraction Operator // | |
console.log(a - b); | |
// Multiplication Operator // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create variable for only the outer block // | |
let i = 22; | |
// Create and loop over inner block variable // | |
for(let i = 0; i < 10; i++) { | |
console.log(i); | |
} | |
// Print outer block variable // | |
console.log(i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assume this creates a connection to a DB // | |
var myDatabaseConnection = new CreateConnectionToDatabase(); | |
// Oops we accidentally overwrote the database connection // | |
myDatabaseConnection = 10; | |
// This would throw an error saying WTF?! how do I run this? | |
myDatabaseConnection.query("SELECT * FROM school"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates a constant variable // | |
const myConstant = 10; | |
// Tries to reassign the variable but will | |
// throw TypeError: invalid assignment to const `myVariable' | |
myConstant = 11; | |
// Prints 10 // | |
console.log(myConstant); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var greeting = "Hello World!"; | |
console.log(greeting); | |
// Reassigns the variable // | |
greeting = "Goodbye!" | |
console.log(greeting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var greeting = "Hello World!"; | |
console.log(greeting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<body> | |
<script> | |
// Your JS code can go here! // | |
</script> | |
</body> | |
</html> |