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 trialBen Thornton
1,605 Points1st task becomes broken when trying to check the third step.
I have written this code three times and have watched the video the same amount. Not sure if I am making a syntactical mistake for the variable creation or the conditional statement. The first 2 tasks get checked and work fine but when I add the else clause then it says that my Task 1 no longer works.
var answer = prompt("What is the best programming language?")
if (answer === "JavaScript") {
document.alert("You are correct")
} else {
document.alert("JavaScript is the best language!")
}
<!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>
1 Answer
Damien Watson
27,419 PointsHi Ben,
Rather than document.alert
just use alert
. It is also good practice to finish each line with a semicolon ;
.
var answer = prompt("What is the best programming language?");
if (answer === "JavaScript") {
alert("You are correct");
} else {
alert("JavaScript is the best language!");
}
Rich Donnellan
Treehouse Moderator 27,696 PointsRich Donnellan
Treehouse Moderator 27,696 PointsYo Damien!
When writing inline code, use the back tick (`) instead of the single quote ('). On that note, the valid syntax for JavaScript is ```javascript not ```js.
Check out this handy post!
Cheers!
Damien Watson
27,419 PointsDamien Watson
27,419 PointsHi Rich, Good to know. Oh, I wasn't trying to write inline code just highlighting the word, didn't know you could... haha.
Both 'js' and 'javascript' seem to be valid? Also 'objc' works but is not listed.
var test = "js";
var test = "javascript";
id test = "objc";
Ben Thornton
1,605 PointsBen Thornton
1,605 PointsThank you so much Damien! That was the problem!