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

ab199
Full Stack JavaScript v2 Techdegree Student 17,446 PointsWhat is wrong with my code? (JavaScript Basics: Stage 2 - Challenge)
var noun = prompt("Enter a noun: ");
var verb = prompt("Enter a verb: ");
var adjective = prompt("Enter an adjective: ");
var sentence = "<h2>I am a " + noun;
sentence += " that is " + verb;
sentence += " on a " + adjective + " day.</h2>";
document.write(sentence);
Brackets, the text editor, is giving me the following errors:
2 JSLint Problems
×
1 'prompt' was used before it was defined. var noun = prompt("Enter a noun: ");
7 document.write can be a form of eval. document.write(sentence);
What are these errors?
1 Answer

Marcus Parsons
15,719 PointsHey Yan,
It's not that your code is wrong per se, but JSLint is saying that prompt
and document.write
should not be used in production code. If you go to http://www.jslint.com and paste your code into the text area, and then at the very bottom of the page click "In development" under the "Assume" category, you'll see your errors go away. These types of functions are only meant to be used to test code (development mode) which is what you're doing.
In fact, if you use jQuery at all, JSLint will pop up with so many errors, your head will spin. It will say a vast array of things are undefined, no pun intended. JSLint only scans the code of the page it is currently on, so it can't take into account that there might just be other scripts defined before this one that give you some awesome tools such as the jQuery library. It's not the best method of testing code, but it is good for testing small blocks of pure JavaScript that don't have to work with any other scripts.
ab199
Full Stack JavaScript v2 Techdegree Student 17,446 Pointsab199
Full Stack JavaScript v2 Techdegree Student 17,446 PointsThanks a lot, Marcus!
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsYou're welcome, Yan! I saw where you marked this as best answer, but now it's not for some reason?