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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Iterating through an Array

use for loop

use a for or while loop to iterate through value

script.js
var temperatures = [100,90,99,80,70,65,30,10];

if(temperatures ==='100---10) {
   alert(temprature degrees!)
  }
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

2 Answers

Im confused at what you want.

Some problems with this and people wont be able to solve it until they are fixed. Ill psuedo code the problems(which means to write what the code should do rather than write it out).

  1. Your string in the if statement looks like it says "if tempratures are exactly equal to 100-10(or 90), then alert a string." I think you mean to say "if tempratures <= 100 and tempratures are >= 10, then alert a string."
  2. You did a math problem in the if statement but you did the math problem with a half-opened string. Remove the single-quote(').
  3. The alert does not have a string in it. Its almost a function. To make it a string, surround the words in a quote or double-quote.
  4. 100---10 is not a thing. I think you are trying to do any numbers between 100 and 10. You would need check each value from your loop to see if its greater than 10 or less than 100. I know, its annoying, but it isnt too hard, trust me. ;)
  5. A for loop and a while loop would both work but it looks like your if statement wouldnt work regardless. All of your values are between 100 and 10. If your array had another value that was too large, it would would show a different result. But right now, every result would show the same if repaired.
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

HI there, Aaron Loften! I took the liberty of changing your comment to an answer. Besides marking the question as "answered" on the forums it also allows for voting on your answer and possible selection of "Best Answer". Thanks for helping out in the Community! :sparkles:

Are you trying to simply have an alert for all of the temperatures? If so, a for loop is very easy to use. you would start off with i set to 0; have it stop to less than temperatures.length. Then, inside the for loop, in order for it to produce that temperature you access it as the index (e.g. temparatures[i]) plus whatever string you want it to output. However, if you need to have it check for it to be within a certain range, you would want to compare it using an if statement. Hope that helps!