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
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
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
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
/* | |
This prints out the numbers from 0 to 9 | |
*/ | |
// Initialize | |
var i = 0; | |
// Evaluate | |
while(i < 10) { | |
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
/* | |
Prints out the values from 0 to 9 | |
*/ | |
// Initialization, Evaluation, and Increment | |
// all in one line | |
for(var i = 0; i < 10; i++) { | |
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
// Initialize | |
var i = 0; | |
do { | |
console.log(i) | |
// Increment | |
i++; | |
} | |
// Evaluate | |
while (i < 10); |
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 an object car with some attributes // | |
var car = { | |
brand:"Honda", | |
year:2018, | |
kms:2500 | |
}; | |
// Loops through the attributes in the object | |
for (var attribute in car) { | |
console.log(attribute + ": " + car[attribute]); |
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 an array of fruits // | |
var fruits = ['Orange', 'Banana', 'Apple']; | |
// Loop through the values in that array | |
for (var fruit of fruits) { | |
console.log(fruit); | |
} |
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 an array // | |
var array = []; | |
// Another way of creating an array of size 2 // | |
var objectArray = new Array(2); | |
// Creates an array with some data already in it // | |
var arrayWithData = [1, 2, 3, 4]; | |
// Adds a value to the array // |