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 trialRachel Bailey
8,862 PointsIterating through an array quiz
Hi! I don't know what I'm doing wrong, but it keeps saying that I'm not logging my array items in order. Any help would be great!
Thanks! -Rachel
var temperatures = [100,90,99,80,70,65,30,10];
function printList(list) {
for(i = 0; i < list.length; i += 1) {
console.log(i);
}
}
printList(temperatures);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Jennifer Nordell
Treehouse TeacherThis one line is the culprit!
console.log(i);
Here, you're printing out the value of i. Not the value at the list index of i. The line you need is:
console.log(list[i]);
Rachel Bailey
8,862 PointsIt worked!!! Thank you!!!!!!
Jared Brandon
8,674 PointsCan you explain why this prints them out in order by value? I don't understand where the program is being told to do that. Thanks!
tracy
32,769 PointsDuh me. Great eye Jennifer!
tracy
32,769 Pointstracy
32,769 PointsHi Rachel,
I think you're almost there: in the temperatures variable you have 90 between 100 & 99, instead of between 99 & 80.
Good luck!