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

Double RR
16,272 PointsJavascript Errors??
Why is jslint and js validator claiming errors when you guys are the best of the best . After all the code was placed the browser came up empty. But on the workspace it's fine.
function randomNumber(upper) {
return Math.floor(Math.random() * upper) + 1;
var counter = 0;
while (counter < 10) {
var randNum = randomNumber(6);
document.write(randNum + ' ');
counter += 1;
}
/*===================Errors???===================*/
Missing 'use strict' statement.
return Math.floor(Math.random() * upper) + 1;
2 3 2 Unexpected character '(space)'.
3 4 3 Unreachable 'var' after 'return'.
var counter = 0;
4 5 3 Expected 'while' at column 5, not column 3.
while (counter < 10) {
5 6 5 Expected 'var' at column 9, not column 5.
var randNum = randomNumber(6);
6 6 9 Don't declare variables in a loop.
var randNum = randomNumber(6);
7 7 5 Expected 'document' at column 9, not column 5.
document.write(randNum + ' ');
8 8 5 Expected 'counter' at column 9, not column 5.
counter += 1;
9 9 3 Expected '}' at column 5, not column 3.
}
10 10 3 Expected '(end)' at column 1, not column 3.
Showing 1 to 10 of 10 entries
2 Answers

Dave McFarland
Treehouse TeacherHi Shay Patrick
There are a few things going on here, and let's see if I can tackle them all clearly:
- The code you posted isn't correct JavaScript. It will produce a syntax error because the function isn't correctly closed with a closing }. I believe that the code I show in the video and include in the workspaces doesn't replicate this error. If it does, please let me know, so I can update it. This is the correct version of the code:
function randomNumber(upper) {
return Math.floor(Math.random() * upper) + 1;
}
var counter = 0;
while (counter < 10) {
var randNum = randomNumber(6);
document.write(randNum + ' ');
counter += 1;
}
But even running this code through JSLint will produce errors.
- JSLint is notoriously picky. Many JavaScript developers don't use it because it produces "errors" that aren't actually syntax errors -- simply stylistic decisions that JSLint disagrees with. For example this error
Expected 'var' at column 9, not column 5.
is given because that line of code is indented 9 spaces instead of 5. My personal style is to use 2 spaces when indenting a line of code -- this too, would produce an "error" from JSLint.
Most developers use "linters" like JSLint (though JSHint is more popular, because it's more forgiving) to help enforce certain best practices. You'll notice that the more popular one is JS "Hint" meaning it's just providing hints to help guide you. In fact, both JSLint and JSHint let you customize their reporting so that they can conform to your programming style.
In other words you should always take linters with a grain of salt.

Double RR
16,272 PointsHey Dave thanks for the heads up on the lints and yes it was the closing curly brace ("my bad"). Also just to shout you and the whole teamTreeHouse staff for making this complex learning not feel as complex as it really is. You guys are intelligent magicians, again Dave thanks for the assist!!