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

Keep getting syntax error

Don't understand what is wrong with my if statement.

app.js
var answer = prompt ("what is the best programing language?");
if (answer.toUpperCase() ==== RUBY){
  document.write( "<p>That's right!<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>

4 Answers

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

In your example RUBY should be a string so you need to surround it with quotes on the comparison.

An there's no "====" operator in JavaScript :

// "==" : Simple comparison operator, ex:
1 == "1" // => true

// "===" : Strict comparison operator (check for type too), ex:
1 === "1" // => false

var answer = prompt ("what is the best programing language?"); if (answer.toUpperCase() === "JAVASCRIPT"){ document.write( "<p>That's right!<p>"); }

This is how I fixed it by now it's asking if I used windows alert and I don't know what it means.

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

Humm that's surely because you need to open dialog than writing in document. So do not use "document.write", but the "window.alert" function which open a dialog

Haven't learned that yet and wasn't used in the example but I'll try it.

Alert and window.alert are the same? Thought that would make a difference.

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

Like it's said in the course, all global variable and function are part of window.