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

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,693 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]) ;