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 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.

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

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 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 :)