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

this is exactly how he's written in his sample quiz example

in the example this is how the instructor says to do it

app.js
var answer=prompt("What is the best programming language?");
if answer===="JavaScript";
 document.write (<p>"You are correct" </p>)
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>
Justinas Vebra
Justinas Vebra
1,053 Points

Correct syntax is this:

var answer = prompt("What is the best programming language?");
if (answer === "JavaScript" ) {
    document.write ("<p>You are correct</p>");
}

Make sure you compare your code and mine and see (understand as well) the differences.

  • Conditional statements have their conditions wrapped inside of brackets and are followed by a code block wrapped inside of curly brackets.
  • Comparison operator is either == or ===. The difference between them is one is abstract comparison operator, the other is strict comparison operator.

3 Answers

Steven Parker
Steven Parker
231,275 Points

Perhaps it's not quite "exactly" the same .. some differences are:

  • the conditional expression following an "if" should be enclosed in parentheses
  • the conditional expression should not be followed by a semicolon
  • a strict equality test operator has 3 equal signs, not 4
  • the instructions ask you to use the alert function, not "document.write"
  • the "alert" function doesn't do HTML processing, you won't need any paragraph tags

I wrote it exactly as you advised justinas vebra. it still won't work

Steven Parker
Steven Parker
231,275 Points

That sample isn't quite correct — try the hints I've given you. :wink:

I did. I've drawn a complete blank for the last two hours. I don't know why. I was trying to complete the requisite work for code Louisville. I really appreciate all the help everyone gave. Including you

Steven Parker
Steven Parker
231,275 Points

Kim Dallas — Learning a new skill goes better in measured doses. You may have just been cramming too much into a short time.

Remember you can mark a question solved by choosing a "best answer".