Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Bert Witzel
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Bert Witzel
Treehouse Project Reviewer

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.

Bert Witzel
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Bert Witzel
Treehouse Project Reviewer

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.