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 Arrays Loop Through Arrays Loop Through an Array

I am getting an error that says “undefined is not an object”. Which part of the code is that referring to?

script.js
const temperatures = [100, 90, 99, 80, 70, 65, 30, 10];

for( let i = 0 ; i> temperatures.length; i++) {
 console.log(temperatures[i]);
}

3 Answers

Sometimes these quizzes aren't the best at identifying what the problem is, in your case you have i > temperatures.length when it should be i < temperatures.length:

const temperatures = [100, 90, 99, 80, 70, 65, 30, 10];

for (let i = 0; i < temperatures.length; i++) {
  console.log(temperatures[i]);
}

Thank you for catching that. However I am still getting the same error message.

Hmm, I just posted it in the challenge again and I passed it okay. Make sure to not paste const temperatures again if you are copying and pasting the code above, that's the only thing I can think might be the problem.

My code worked when I tested it outside of the challenge. And it was finally accepted after I refreshed the page and restarted the challenge. I think I was having an issue with the tree-house site not my actual coding.