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

18 January 2014
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 = numSheep * 4; 
  console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!"); 
}