When to "while" and when to "for"


#1

*So my code passes but nothing prints to the console log not sure what Im missing
thanks for your help!!!*

var cashFlow = true;
var soloLoop = function(){
  while(cashFlow){
    console.log("Show me the money");
    cashFlow = false;
}

var i = 0;
for (var i = 1; i < 10; i++) {
    console.log(i);
}
};


#2

Hi you should call the function soloLoop


#3

Ive changed my code to this still nothing prints to the log

var soloLoop = true;
var soloLoop = function(){
while(soloLoop){
console.log("Show me the money");
soloLoop = false;
}
soloLoop()

var i = 0;
for (var i = 1; i < 10; i++) {
console.log(i);
}
};


#4

You closed you function after the for loop so you should put the call function

var soloLoop = true;
var soloLoop = function(){
    while(soloLoop){
        console.log("Show me the money");
        soloLoop = false;
    }
soloLoop() <-- #remove it here

    var i = 0;
    for (var i = 1; i < 10; i++) {
        console.log(i);
    }
};
soloLoop()  <-- #put i here

#5

thanks its printing to the log but im getting this error at the end of the log "TypeError: soloLoop is not a function"

var soloLoop = true;
while(soloLoop){
console.log("Show me the money");
soloLoop = false;

var i = 0;
for (var i = 1; i < 10; i++) {
console.log(i)
}
};
soloLoop()


#6

you code was like that

var soloLoop = true;
var soloLoop = function(){
    while(soloLoop){
        console.log("Show me the money");
        soloLoop = false;
    }
    var i = 0;
    for (var i = 1; i < 10; i++) {
        console.log(i);
    }
};
soloLoop()  <-- #put i here

then your code became (You change it)

var soloLoop = true;
while(soloLoop){
    console.log("Show me the money");
    soloLoop = false;
} <-- //add this one
var i = 0;
for (var i = 1; i < 10; i++) {
    console.log(i)
    }
}; <-- remove this
soloLoop()

since you remove the function soloLoop you should also remove the call function


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.