Why doesn't this block log to console while the loops run?


#1


This exercise (free, make 2 loops)


The code passes the test, but neither of the console.logs actually log to console.


var firstVar = "22"

var firstFunc = function() {
    for(i=2;i<7;i++) {
        console.log("Whatup!")
        while(firstVar>19) {
            firstVar--
            console.log("Ayy!")
        };
    };
};

firstFunc


#2

Have you tried using parenthesis on your firstFunc? :wink:

If you want to call your function, you should call it like that - firstFunc()


#3

That worked, but I guess I am missing the concept a bit, because in this other exercise loop my console logs that (count) var as false but doesn't log my string in the for loop??

var go=false
var count = 1

var now= function(){
    do{
        for(i=1;i>4;i++){
            console.log("This is cool")
            while(count===1){
                console.log(count)
                count--
            }
        }
    } while(go)
};

now()

#4

this also will not log console.log commands inside the loops. am I on crazy pills or what?

// Write your loop below!
var go = function(){
    for(i=0;i>=4;i++){
    console.log("Driving")
    j=i
    while(j<2){
        console.log("fast")
        j++
    }
}
}
go()

#5

The loop never runs. Should be < 4 or <= 4 so that condition is true at the start of the loop.


#6

THANK YOU! @mtf, I had been making loops with a 'condition to end' instead of 'until condition is no longer met'

thank you. now all the loops I've been having trouble with make sense again!
It was letting me pass because the loops weren't infinite, because they never ran the code at all. You're a godsend


#7

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