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 trialMustafa Malik
Courses Plus Student 1,491 PointsCan't get through this task!
have to use a loop to convert this multiple code in to one single running code.
console.log(2);
console.log(4);
console.log(6);
console.log(8);
console.log(10);
console.log(12);
console.log(14);
console.log(16);
console.log(18);
console.log(20);
console.log(22);
console.log(24);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
6 Answers
Julian Gutierrez
19,201 PointsLooks like your over thinking this a bit. The challenge needs you to use a for loop to count up from one number to another. There is really no need for any random generated numbers. See if you can figure it out following the structure of a for loop below (don't include the quotes).
for(var i = "starting number"; i<="max number"; i+="interval"){
console.log(i);
}
Julian Gutierrez
19,201 PointsFor this challenge you need to use a for loop.
Mustafa Malik
Courses Plus Student 1,491 PointsYes! i know and i did. Don't know what i'm doing wrong.
Julian Gutierrez
19,201 PointsMind posting your code to better help troubleshoot.
Mustafa Malik
Courses Plus Student 1,491 Pointsvar evenNumber = 2 for ( evenNumber >= 24) { Math.floor(Math.random() * 24 ) + 2; console.log(evenNumber); }
This is giving me syntax error. I have also tried to add another variable inside the loop but it still does not work.
Mustafa Malik
Courses Plus Student 1,491 PointsSyntax Error: Parse error
Mustafa Malik
Courses Plus Student 1,491 PointsThank you very much Julian. It was a simple task. You were right i was over thinking it. Thanks again.
Mustafa Malik
Courses Plus Student 1,491 PointsMustafa Malik
Courses Plus Student 1,491 Pointsok but i need to define numbers so i can get the even numbers from 2 to 24.
Mustafa Malik
Courses Plus Student 1,491 PointsMustafa Malik
Courses Plus Student 1,491 PointsSorry!!!! i got it. My bad.