Bug: While Loop not producing correct result


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661

The link above is just the exercise that I discovered this bug on, however this bug exists in all the console lessons for javascript.

Result of the following code in jsfiddle or the chrome console:

1 and
2 and
3 and
4 and
5 and

And here is the result of the following code in the Codecademy console:

1 and
2 and
3 and
4 and
5 and
5

I do not understand why your console adds the extra "5" for the last line. I thought for some time that I was doing it wrong, but instead this seems to be a rendering issue with the codecademy's console. Hope this helps you find a solution for this and that it isn't affecting other sections of the code too. Thanks!


var i = 1;
do {
	console.log(i + " and");
  i++;
} while (i <= 5);


#2

the codecademy console just has this behavior, it is no bug, and actually quit useful that you get echoed the last value, if you are aware of this it can actually help you


#3

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