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 Tracking Multiple Items with Arrays Iterating through an Array

Communication Problem for this test specifically.....

So I keep receiving a communication error every time I go to input the answer for this test.. I'm not sure why, but I figured I'd say something.

Thanks for the hard work. This is an amazing course.

script.js
var temperatures = [100,90,99,80,70,65,30,10];
for(var i=0; i<temperatures.length; i+1) {
  console.log(temperatures[i]);
}
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

4 Answers

Hi Joshua,

I think the challenge is timing out because you've created an infinite loop.

i + 1 doesn't change the value of i You have to add 1 to i and then store the result back in i

You could replace i + 1 with any of the following:

  • i = i + 1 long way to write it
  • i += 1 addition assignment operator. A little shorter.
  • i++ increment operator. This is the one you will probably most commonly see. Might not have been taught in the course though
jerry bremser
jerry bremser
3,941 Points

can you eleborate? is that entire code? if it is it seems youre missing an input option for the user. it never prompts anything at all. again im not 100% sure what the issue is if you could show whole code or lesson reqs.

Hi Jerry,

For future reference, usually a question about treehouse content will have a link to that piece of content over in the right column under "Related content".

In this case there's a direct link to the code challenge that this question is about. There you can review the challenge or test code if needed.

jerry bremser
jerry bremser
3,941 Points

but wouldn't the var i=0 mean it can be anything between 0 and 0.9999999? by adding the +1 at the end im assuming he didnt mean to update the variable 'i' but to make it so 'i' can not be any lower than the number 1? does that sound right? just wondering before i look over it again

Hey Jerry,

This mdn page will tell you what each part of the for loop is for: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for

JASON THAT WAS IT!!!! THANK YOU SOOOOOO MUCH!!!!!!!!!!

You're welcome.