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!

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 Refactor Using a Loop

Xiaolei Wheelock
Xiaolei Wheelock
3,027 Points

my answer runs correctly but the code challenge won't pass it.

I am at JavaScript Loops section. the very last code challenge asked me to replace the repeated console.log with a simple loop code. i did that. var string =' '; for(var i=2; i<=24; i+=2) { string +=i +' '; } console.log(string);

but it kept on saying " Bummer! you logged 1 number but you need to log 12 numbers" I tried in chrome console, it did log 12 numbers. I can't find a way to get pass this code challenge. Please help.

var string =' ';
for(var i=2; i<=24; i+=2)
  string +=i +' ';
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

2 Answers

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,243 Points

Try adding string[i] + ' ':

In your code blog

This should work. If you're still getting the 12 numbers it might be the correct code but the challenge is looking got a specific answer

Hope this helps you :)