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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Introducing Conditional Statements

Add 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?

app.js
var answer = prompt('What is the best programming language?');
var correctAnswer = 'Javascript'; 

if ( answer === correctAnswer ) {
  alert("You are correct");
}
index.html
<!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

I 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");
}

You beat me to it, Mohammed. Well done! :)

Yup, 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!

My code was wrong because I only updated your code that uses string 'Javascript' the 's' was lower case I updated my answer now.

The 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

I 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.

Yup, it was because I had used a lowercase s instead of an uppercase S in 'JavaScript'.

thanks

You'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");
}

Oh, 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.