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 Simplify Repetitive Tasks with Loops Refactor Using a Loop

sami thakur
sami thakur
970 Points

what does it mean by undefined numbers? it works normally if i use it on workspace i think

?

script.js
var stimpy = 2;
while(stimpy > 24){
stimpy += 2
console.log(stimpy);
}
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

John Hill
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
John Hill
Front End Web Development Techdegree Graduate 35,236 Points

Since stimpy is set to 2, it will never be greater than 24 and the while loop will not run.

Maybe you meant to use the less than symbol?

Michael Hulet
Michael Hulet
47,913 Points

It'd be important to use the less that or equals operator here. Either that or compare against 25 instead of 24

Michael Hulet
Michael Hulet
47,913 Points

The checker itself appears to be written in JavaScript. When you or the checker encounters an error of some kind, its internal variable for the count of numbers you've printed is undefined, so that's what it puts into the error message. In your case, you're printing 0 numbers to the console, because the code inside your loop will never run. My suggestion is to use a different operator in the condition of your while loop