Guest User

Untitled

a guest
Nov 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /*
  2. Morph your previous while loop into a for loop that uses the same variable names. Remember, you’ll still need to declare the starting number of sheep and the number of months to print outside the loop. We’ve given you the starting number of sheep again, as well as the amount of months you’ll need to print out for use in the loop parameters. Here’s a solution for the previous while loop for reference:
  3. var numSheep = 4;
  4. var monthNumber = 1;
  5. var monthsToPrint = 12;
  6.  
  7. while (monthNumber <= monthsToPrint) {
  8. numSheep = numSheep * 4;
  9. console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!");
  10. monthNumber++;
  11. }*/
  12.  
  13. // for
  14. var numSheep = 4;
  15. var monthsToPrint = 12;
  16.  
  17. for ( var i = 1; i <= monthsToPrint ; i++ ) {
  18. numSheep = numSheep * 4;
  19. console.log("There will be " + numSheep + " sheep after " + i + " month(s)!");
  20. }
Add Comment
Please, Sign In to add comment