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 trialWally Mostafa
Courses Plus Student 982 PointsCan't seem to get it started at 100
I'm blanking here. An unfortunate side effect to being away from code for a few days. I can't seem to get it to run at 100. That's the error I keep running into. I tried the same list setup as the lesson before. No luck. Any help would be great, would even be interested in knowing if the list method is even needed here. I do think I'm overcomplicating this. Thanks in advance!
var temperatures = [100,90,99,80,70,65,30,10];
function runLoop( tempList) {
var listHTML = '<ol>';
for( var i = 0; i < temperatures.length; i += 1){
listHTML += '<li>' + tempList[i] + '<li>';
}
}
console.log(runLoop(temperatures));
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Wally,
Yeah... you are way overcomplicating this. The answer is only 2 lines of code.
You just need to really read the instructions for the challenge. Challenges are very picky and very specific. Here, it did not ask for a function, so that needs to be deleted. It didn't ask for any type of HTML insertions, so all that... deleted, and the console is supposed to log the number in the array and it has to be inside of the loop.
So, once everything is deleted, your for loop
is correct. And then inside of the for loop
just have the console.log()
log out the numbers... using the temperatures
variable with bracket notation
to get the right number from the array.
Give it another go with this in mind.
Keep Coding! :)
Jon Wood
9,884 PointsI think your code is on the right track, but it may be just more than what the challenge is asking. I think they just wanted a for loop and to log out the value of each array item, so you don't have to create any extra HTML for it.
Wally Mostafa
Courses Plus Student 982 Pointsthank you very much!
robertmaiolo
7,946 PointsI think it just needs a return statement otherwise there's nothing for it to display or echo
Wally Mostafa
Courses Plus Student 982 PointsWally Mostafa
Courses Plus Student 982 PointsThank you very much, super helpful.