11/11 Random number


#1
var count = 0;

for(var i = 0; i <2; i++) {
    console.log("Should loop twice!");
    }
    
while (count < 3) {
    console.log("My name is my name should print 3 times");
    count++;
    }
    
do {
    console.log("This should print 4 times!");
    count++;
    }while(count < 7);

Passes through however, I'm greeted with a random single "6" string at the end of my results. Anything wrong with my solution? or is there anything you would change/do differently?

See:

Should loop twice!
Should loop twice!
My name is my name should print 3 times
My name is my name should print 3 times
My name is my name should print 3 times
This should print 4 times!
This should print 4 times!
This should print 4 times!
This should print 4 times!
6

Thanks


#2

The only issue i see potentially occurring is the random number "6" -- being called by the count variable which isn't likely if i wrote the loops properly.

Thanks again


#3

No, the consoles in codecademy will print a the main variable at the end of your code to make sure you did it right. it does this so that the "passing condition" is triggered and it's completely intentional. As long as you're not failing the course you're good to go. Again this is intentional, and it would not show up on an actual project using JavaScript.


#4

It’s not only about the CC console but about any web console in actual js project you’d just not use a console as output but just as a debugging tool :slight_smile:

@bijjjr The thing is that the last value of your code is echoed by the console. This is a quick response and you can use it to get something displayed without using console.log. But as it only works for the last one better use console.log if you want a reliable output. Also if an exercise asks for console.log this doesn not work. So what you see is not a random number but the value of count++. And as lolman said as long as it is not an error you don’t need to bother about it. Also you can run this in labs repl.it to see that it is really just a console echo (as it is displayed in a different color).