Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Rich Braymiller
7,119 PointsCreate a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) me
Ive looked at other answers for this question...and I'm clueless to why this isn't passing.....
var num;
for(num = 4; num <= 156; ) {
console.log("Number " + num)
}
1 Answer
Michael Hulet
47,913 PointsI can see at least 3 reasons this might not be passing. First is that your for loop syntax is incorrect. You forgot to write the 3rd part of the loop, where you write the code that is run at the end of every loop. In this case, you want to increment num by 1 at the end of each loop, so your loop should look something like this:
var num;
//Notice the incrementor as the 3rd part of the loop
for(num = 4; num <= 156; ++num) {
console.log("Number " + num)
}
The next reason I could see why it wouldn't be passing is that you forgot your semicolon after the console.log() statement. Adding that in, your code would look like this:
var num;
for(num = 4; num <= 156; ++num) {
//Notice the semicolon at the end of the following statement
console.log("Number " + num);
}
The potential last reason I could see is that the challenge only asks you to print out the number, and not anything before it. In other words, just print out the value of num every iteration, and not the string before it. Making that change, your code would look like this:
var num;
for(num = 4; num <= 156; ++num) {
//You only want to print out the number
console.log(num);
}
If the last snippet doesn't work, let me know, because I can see one last thing that might be causing your code to fail by Treehouse's standards, but I would be surprised