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

Well the condition is the following : if ( === ) {} and I receive a error, I know that it may seam logic.

if ( answer === prompt ) {alert "text"} right ?

app.js
var answer = prompt ('What is the best programming language?');
if ( answer ==== prompt ) { 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>

2 Answers

Hey Besleaga, your syntax is a little bit off. alert() is a JavaScript method belonging to the Window. The long form is window.alert().

First, you have four "=" signs in your conditional. You need only three for exact matching. Next, you have to put the text that you want to alert to the user inside of the parenthesis. Lastly, you need to add the string you're checking for ("JavaScript") inside the if conditional. Here's what I did:

var answer = prompt('What is the best programming language?');
if ('JavaScript' === answer) {
  alert('You are correct');
}
Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

You are on the right track, but there are just a couple of things.

  • First, you have 4 equal signs in the code, and the strict comparison is only 3.
  • Second, you are trying to compare a variable (answer) to a method call (prompt()), and that can't be done. It's also not what the instructions ask for. The instructions want you to compare the variable to the hard-coded string "JavaScript" (and it is case-sensitive).
  • Finally, alert() is a method and needs to have the parenthesis around the passed in parameter for the call.

Give it another go with those corrections. I'm sure you'll get it! :)

Keep Coding! :dizzy: