3. For and a while


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-qDwp0/0/3?curriculum_id=506324b3a7dffd00020bf661


The code works out but it prints something extra.
so after clicking submit, this is what I get;
0
1
2
3
4
I like pines
I like pines
I like pines
6

Can anyone tell me why is there a 6 there and how do i remove it?


Replace this line with your code. 
// Write your loop below!
for(var i=0;i<5;i++){
    console.log(i)
}

var count=4
while(count<7){
    console.log("I like pines")
    count++}


#2

it is just console behaviour, don't worry about it. console is generally only used for debug.


#3

you could of course make sure no variable are changed any more, and the last thing to happen is a console.log:

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

var count=4
while(count<7){
    count++
    console.log("I like pines")
    }

this way, you don't get the "undesired" console output


#4

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