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

Thomas H
Thomas H
Full Stack JavaScript Techdegree Student 4,545 Points

iterating thought a array

Hi everybody, i m stuck at this excercise i don t find the good answer..

Someone can help me ?


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

1 Answer

Maxwell Newberry
Maxwell Newberry
7,681 Points

In your for-loop, you have three parts to the statement. Initializing a variable, setting a condition, and setting the iterator. For your code, you set i to equal 100 whereas your condition only iterates through the loop while i is less than the size of the array temperatures (8). Because of this, the loop defaults to false and never loops through.

You also on Line 3, you reference the current item in the loop using parentheses. In Javascript, we reference a specific item in an array using brackets like this:

console.log(temperatures[i]) ;