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 trialAmad Durrani
4,518 PointsUse a for loop to iterate over the values inside the temperatures array. Start from the first element (100) to the last
Can anyone explain why my code isnt working??
Please & thank you.
const temperatures = [100, 90, 99, 80, 70, 65, 30, 10];
for ( i = 0, i <=temperatures.length; i++ ) {
console.log(temperatures[i]);
}
3 Answers
Rabin Gharti Magar
Front End Web Development Techdegree Graduate 20,928 PointsHey Amad Durrani,
You need to add let
keyword before the initialization
and add a semi-colon
instead of comma
.
Here's the final version:
const temperatures = [100, 90, 99, 80, 70, 65, 30, 10];
for ( let i = 0; i <=temperatures.length; i++ ) {
console.log(temperatures[i]);
}
To learn more about different loops
, you can visit this link: https://www.tutorialrepublic.com/javascript-tutorial/javascript-loops.php
Hope this helps!
Amad Durrani
4,518 PointsI also tried
const temperatures = [100, 90, 99, 80, 70, 65, 30, 10]; for ( i = 0, i < temperatures.length; i++ ) { console.log(temperatures[i]); }
Still doesnt work.
Amad Durrani
4,518 Pointsfinally got it
for ( let i = 0, i < temperatures.length; i++ ) { console.log(temperatures[i]); }