Code School: JavaScript Part 2 (2.7 Problem Solving with Conditionals)

18 January 2014

var numSheep = 4;
var monthsToPrint = 12;

for (var monthNumber = 1; monthNumber <= monthsToPrint; monthNumber++) {
if (monthNumber % 4 === 0){
reduced = numSheep * .75;
numSheep = numSheep - reduced;
console.log("Removing " + reduced + " sheep from the population. Phew!");
} else if (numSheep > 10000) {
reduced = numSheep * .5;
numSheep = numSheep - reduced;
console.log("Removing " + reduced + " sheep from the population. Phew!");
}

numSheep*=4;
console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!");
}