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 trialPage Petty
813 PointsMy console says it's right... so why are you Bumming me out???
Why am I getting X Bummer?
var even = 2;
while (even < 24 ) {
console.log(even);
even += 2;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
KRIS NIKOLAISEN
54,972 PointsYou are only logging 2 to 22. You need to include 24.
KRIS NIKOLAISEN
54,972 PointsA while loop executes while a condition is true (in this case even < 24). With your code once even = 24 the condition is no longer met. You can fix it with a condition of even <=24 or even < 25. Either one will pass the challenge.
If you would like to see an alternative try the first example here
What console are you using?
Page Petty
813 Pointsactually, those will print 26.
var even = 2;
while (even <= 24 ) { console.log(even); even += 2; } head_vendor-a10c14c9…ed21c5641a3.js:1380 2 head_vendor-a10c14c9…ed21c5641a3.js:1380 4 head_vendor-a10c14c9…ed21c5641a3.js:1380 6 head_vendor-a10c14c9…ed21c5641a3.js:1380 8 head_vendor-a10c14c9…ed21c5641a3.js:1380 10 head_vendor-a10c14c9…ed21c5641a3.js:1380 12 head_vendor-a10c14c9…ed21c5641a3.js:1380 14 head_vendor-a10c14c9…ed21c5641a3.js:1380 16 head_vendor-a10c14c9…ed21c5641a3.js:1380 18 head_vendor-a10c14c9…ed21c5641a3.js:1380 20 head_vendor-a10c14c9…ed21c5641a3.js:1380 22 head_vendor-a10c14c9…ed21c5641a3.js:1380 24 26  ​------- var even = 2;
while (even < 25 ) { console.log(even); even += 2; } head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 2 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 4 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 6 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 8 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 10 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 12 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 14 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 16 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 18 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 20 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 22 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 24 26
Carl Evison
2,656 PointsYour last console.log will be 22 after that you have incremented the number by 2 which will mean the variable even
is now 24.
Your conditional statement is then saying is 24 less than 24 and because It isn't less, it's the same the loop stops running because it only runs if the condition is true.
Page Petty
813 PointsPage Petty
813 Pointswell, my console shows 2 - 24.
var even = 2;
while (even < 24 ) { console.log(even); even += 2; } head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 2 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 4 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 6 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 8 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 10 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 12 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 14 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 16 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 18 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 20 head_vendor-a10c14c9feb9430f7c34eae5a45d4840a07bfc74111f6409c51a3ed21c5641a3.js:1380 22 24