Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,219 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
Treehouse Moderator 47,835 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
MOD
Michael Hulet
Treehouse Moderator 47,835 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