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

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

Lynn Krogseng
Lynn Krogseng
1,254 Points

My code works. It's not being accepted by Treehouse challenge.

This code creates a for loop, printing 4 as the first number and prints every number upto and including 156. The system keeps telling me the console should print 4 as the first number. What is the problem here? My Javascript code: for (i=4; i<=156; i++) { console.log("The number is: " + i + "."); }

script.js
for (i=4; i<=156; i++) {
  console.log("The number is: " + i + ".");
}

2 Answers

jason chan
jason chan
31,009 Points
for(var i = 4; i < 157; i++) 
{
console.log(i)
}

Try that.

Do not cocat the string

console.log("The number is: " + i + ".");

here you doing concatenation. It's asking only for numbers

Lynn Krogseng
Lynn Krogseng
1,254 Points

Right after I posted message, I realized it really just wanted the number printed. Thank you.