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 trialErin Agobert
4,781 PointsI'm getting the error that I should log the numbers in order. The JS console shows all numbers are in order. Pls Help.
I thought I understood this lesson, but now I'm thoroughly confused.
var temperatures = [100,90,99,80,70,65,30,10];
var tempList="<ol>";
for ( var i = 0; i < temperatures.length; i += 1) {
tempList += "<li>" + temperatures[i] + "</li>";
}
tempList += "</ol>";
console.log(temperatures);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Erin Agobert
4,781 PointsThank you Tim and Steven! I thought I tried both ways, but I'm pretty sure I missed something. I tried the challenge 2 ways....
//Simplified as suggested and moving the console.log "inside" the loop.//
var temperatures = [100,90,99,80,70,65,30,10];
for ( var i = 0; i < temperatures.length; i += 1) { console.log(temperatures[i]); }
//AND keeping the ordered list and moving the console.log "inside" the loop.//
var temperatures = [100,90,99,80,70,65,30,10];
var tempList="<ol>";
for ( var i = 0; i < temperatures.length; i += 1) { tempList += "<li>" + temperatures[i] + "</li>"; tempList += "</ol>"; console.log(temperatures[i]); }
1 Answer
Steven Parker
231,275 PointsThe challenge instructions say, "Inside the loop, log the current array value to the console", but the code here is building a string in side the loop and logging it after the loop.
Also, as Tim suggested, you would not use HTML tags when logging to the console. They do not perform the same job in the log as they do on the page.
Tim Renner
11,163 PointsTim Renner
11,163 PointsGood job! You did what was asked, and then some. The challenge isn't looking for the <ol><li> tags wrapped around it. So you can simplify it to console.log(temperatures[i]) and put it inside the for...loop so it runs once for every array item. Wrapping with HTML is good for presentation, while logging to the console is plain text.