Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Kevin Lewis
seal-mask
.a{fill-rule:evenodd;}techdegree
Kevin Lewis
Front End Web Development Techdegree Student 9,667 Points

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,372 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
Kevin Lewis
seal-mask
.a{fill-rule:evenodd;}techdegree
Kevin Lewis
Front End Web Development Techdegree Student 9,667 Points

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,372 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

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

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