JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

Works in workspaces but not being accepted in code challenge. Why not?

When I preview this code in workspaces, it logs 4-156 to the console, as the challenge requires.

However, I'm getting a "Bummer"-message when I check the work in the challenge, saying "You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times." I don't understand what's going wrong.

var html = ' ';

for (var i = 4; i <= 156; i += 1){ html += i + ' '; }


var html = ' ';

for (var i = 4; i <= 156; i += 1){
  html += i + ' ';


Problem solved.

1 Answer

Steven Parker
Steven Parker
207,976 Points

It looks like you already discovered that the challenge wanted you to log each number individually. :wink:

This is a also a good opportunity to remind other students to be careful about testing challenges in external IDEs and REPLs. It's easy to misinterpret the objective and become frustrated when the code seems to produce a "right" answer.

It's also easy to make assumptions about the test data and to actually get correct results with code that will perform differently when the validator tests it more rigorously with its own data.

Happy coding, everyone!