M-Drummond
1/18/2016 - 12:44 AM

javascript loop

javascript loop

var numSheep = 4; // number of sheep
var monthNumber = 1; // counting month
var monthsToPrint = 12; // max length of loop

while (monthNumber <= monthsToPrint) { // while months is less than the max length
  numSheep *=4; // multiply the number by 4
  console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!" ) ; // output concat. string
  monthNumber++ ; // increment the month - will only occur below the maximum amount.
}