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 trialKevin Lewis
Front End Web Development Techdegree Student 9,667 PointsKeep getting syntax error
Don't understand what is wrong with my if statement.
var answer = prompt ("what is the best programing language?");
if (answer.toUpperCase() ==== RUBY){
document.write( "<p>That's right!<p>");
}
<!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
Courses Plus Student 18,373 PointsIn 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
Christopher Debove
Courses Plus Student 18,373 PointsHumm 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
Kevin Lewis
Front End Web Development Techdegree Student 9,667 PointsHaven't learned that yet and wasn't used in the example but I'll try it.
Christopher Debove
Courses Plus Student 18,373 PointsThat's the first thing you learn : alert("Hello world")
Kevin Lewis
Front End Web Development Techdegree Student 9,667 PointsAlert and window.alert are the same? Thought that would make a difference.
Christopher Debove
Courses Plus Student 18,373 PointsLike it's said in the course, all global variable and function are part of window.
Kevin Lewis
Front End Web Development Techdegree Student 9,667 PointsKevin Lewis
Front End Web Development Techdegree Student 9,667 Pointsvar 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.