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 trialGena I
540 Pointsnot sure why task 1 isn't passing
help
var answer = prompt('What is the best programming language?');
if (answer==='JavaScript') {
alert("You are correct");
}
else {
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>
Tizmiz Tizzer
1,040 PointsSorry about that, not familiar with Javascript, but your problem is that you forgot the last } at the end of your else statement.
4 Answers
Brodey Newman
10,962 PointsHey Gena!
Try writing your else on the same line as your closing 'if' curly bracket. To pass this challenge, your code should look like mine below. Also, your else statement isn't closed properly.
if (answer === 'JavaScript' ) {
alert("You are correct");
} else {
alert("JavaScript is the best language!");
}
Gena I
540 Pointsvar answer = prompt('What is the best programming language?');
if (answer=='JavaScript') {
alert("You are correct");
}
else {
alert("JavaScript is the best language!"); }
still not working now task 2 isn't
Tizmiz Tizzer
1,040 PointsTry this
var answer = prompt('What is the best programming language?');
if (answer==='JavaScript') {
alert("You are correct");
}
else {
alert("JavaScript is the best language!")
}
Added the last curly brace and switched answer to make it have 3 equal signs. This code worked for me
Brodey Newman
10,962 PointsThe code worked for me below.
var answer = prompt('What is the best programming language?');
if (answer === 'JavaScript') {
alert('You are correct!');
} else {
alert('JavaScript is the best language!');
}
Larry Cousino
23,127 PointsHi Gena,
Prior users have helped you to get the solution.
A good practice when dealing with parenthesis, brackets and curly braces is right after opening one, immediately close it, so you don't forget to. Then put your code within. You can usually catch it, but once you start having a bunch of them open, it can be time consuming to locate and resolve issues.
Good luck and welcome to Treehouse!
Jeff McDivitt
23,970 PointsYou are forgetting the closing braces and the semicolon
var answer = prompt('What is the best programming language?');
if (answer === 'JavaScript') {
alert('You are correct');
} else {
alert('JavaScript is the best language!');
}
Gena I
540 PointsGena I
540 Points2 equal signs didnt work