8. When to while and when to for answer sample


#1

var count = 5;

while(count > 0){
console.log("I sold the puppy");
count = count - 1;
for (var j = 1; j > 0; j--) {
console.log("I will buy a cat!");

         };

}


#2

Do you think you could phrase this into a question? I'm not sure if you're trying to show us something or there's a question you'd like to ask. Either way just reply to this post and I'll answer it!


#3

hi i having problems with this also and i dont know if im on the right path. my code keeps saying unexpected token

var greeting = function(greeting); {
while(greeting === true) {
console.log("hello1!");
}
greeting = false
};
for(var i = 0; i < 10; i++) {
console.log(i);
};


#4

hello @lesleymashaya

you don't need the semicolon after var greeting = function(greeting);

use :
var greeting = function(greeting)

you need to move greeting = false into your while loop because for the moment it's an infinite loop

like this :

while(greeting === true) {
    console.log("hello1!"); 
    greeting = false;
}

and don't forget semicolon after each instructions