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 trialJiten Mehta
Front End Web Development Techdegree Graduate 21,209 PointsWhich for loop method is best?
Hi guys, im revisiting the JaavaScript Loops, Arrays and Objects course.
I came across this challenge and struggled a little.
I used the following loop. This works in the console but did not pass the challenge. I used const instead of var.
const temperatures = [100,90,99,80,70,65,30,10];
for (let i = 0; i < temperatures.length; i++){
const temp = temperatures[i];
console.log(temp)};
In order to pass the challenge i had to use,
var temperatures = [100,90,99,80,70,65,30,10];
for (var i = 0; i < temperatures.length; i ++){
console.log(temperatures[i])};
Since both work (in the console at least) which method would be best to log out temperature?
2 Answers
Steven Parker
231,110 PointsUsing "let" is a more modern choice and would generally be considered "best practice". The evaluation engine for this challenge is probably older than ES6 and did not recognize the newer keyword.
Jiten Mehta
Front End Web Development Techdegree Graduate 21,209 PointsCheers Steven that's good to know.
Happy Holidays!