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 numSheep = 4; | |
var monthsToPrint = 12; | |
for(var monthNumber = 1; monthNumber <= monthsToPrint; monthNumber++){ | |
numSheep*=4; | |
console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!"); | |
} |
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 currentGen = 1; | |
var totalGen = 19; | |
var totalMW = 0; | |
while(currentGen<=4){ | |
totalMW += 62; | |
console.log("Generator #" + currentGen + " is on, adding 62 MW, for a total of " + totalMW + " MW!"); | |
currentGen++; | |
} | |
for(currentGen = 5; currentGen <= totalGen; currentGen++){ |
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 totalCars = 10; | |
var carsOperational = 8; | |
var carNumber = 1; | |
for (var carNumber = 1; carNumber <= totalCars; carNumber++) { | |
if (carNumber <= carsOperational){ | |
console.log("Car # " + carNumber + " is running."); | |
}else{ | |
console.log("Car # " + carNumber + " is not running."); | |
} |
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 num = 10; | |
while(num > 0) { | |
if (num % 2 === 0) { | |
console.log(num); | |
} | |
num--; | |
} |
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 numSheep = 4; | |
var monthsToPrint = 12; | |
for(var monthNumber = 1; monthNumber <= monthsToPrint; monthNumber++) { | |
if (numSheep > 10000) { | |
numSheep = numSheep / 2; | |
console.log("Removing " + numSheep + " sheep from the population. Phew!"); | |
} | |
numSheep*=4; | |
console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!"); | |
} |
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
function prime(n) { | |
var isPrime = true; | |
for (var i = 2; i < n && isPrime; i++) { | |
if (n % i === 0) { | |
isPrime = false; | |
} | |
} | |
return isPrime; | |
} |
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
for (var i = 8 ; i < 120; i+= 12) { | |
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
for (var i = 10; i >= 0; 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
var junk = ["uno", "dos", 3, 4 ]; | |
console.log(junk); |
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 cities = ["Melbourne", "Amman", "Helsinki", "NYC"]; | |
for (var i = 0; i < cities.length; i++) { | |
console.log("I would like to visit " + cities[i]); | |
} |