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 trialBob Sutherton
20,160 PointsAdd a variable named answer and use the prompt() method to ask the question 'What is the best programming language?'
I have tried this a couple of different ways and it keeps rejecting my answer. Does anyone see the problem?
var answer = prompt('What is the best programming language?');
var correctAnswer = 'Javascript';
if ( answer === correctAnswer ) {
alert("You are correct");
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
3 Answers
Mohammed Khalil Ait Brahim
9,539 PointsI think your error is putting the answer in a variable try doing this
var answer = prompt('What is the best programming language?');
if ( answer === 'JavaScript' ) {
alert("You are correct");
}
Bryan Tidwell
3,473 PointsYou're just ahead of the game on this one, Brock. Try simplifying it a little bit by avoiding the second variable:
var answer = prompt('What is the best programming language?');
if (answer === "JavaScript") {
alert("You are correct");
}
Bob Sutherton
20,160 PointsOh, I see. It is the lowercase S that was the problem, not the parenthesis. That makes sense! Thanks for clearing that up Mohammed Khalil Ait Brahim.
Bryan Tidwell
3,473 PointsBryan Tidwell
3,473 PointsYou beat me to it, Mohammed. Well done! :)
Bob Sutherton
20,160 PointsBob Sutherton
20,160 PointsYup, that minute difference made all the difference in this case. I had tried this way first, but must have done the parentheses the way Mohammed Khalil Ait Brahim did and it rejected it.
Thanks to both of you!
Mohammed Khalil Ait Brahim
9,539 PointsMohammed Khalil Ait Brahim
9,539 PointsMy code was wrong because I only updated your code that uses string 'Javascript' the 's' was lower case I updated my answer now.
Bob Sutherton
20,160 PointsBob Sutherton
20,160 PointsThe quiz rejected it and it rejected mine when I tried it that way originally, although it was working in the browser. Mohammed Khalil Ait Brahim
Bryan Tidwell
3,473 PointsBryan Tidwell
3,473 PointsI can't imagine the space in the parenthesis was the reason. The capital "s" in JavaScript maybe? Mohammed's code looks solid to me. Weird.
Bob Sutherton
20,160 PointsBob Sutherton
20,160 PointsYup, it was because I had used a lowercase s instead of an uppercase S in 'JavaScript'.
Mars Epaecap
5,110 PointsMars Epaecap
5,110 Pointsthanks