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

not sure why task 1 isn't passing

help

app.js
var answer = prompt('What is the best programming language?');
if (answer==='JavaScript') { 
  alert("You are correct"); 
}
else {
  alert("JavaScript is the best language!")
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>

2 equal signs didnt work

Tizmiz Tizzer
Tizmiz Tizzer
1,040 Points

Sorry 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
Brodey Newman
10,962 Points

Hey 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!"); }

var 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
Tizmiz Tizzer
1,040 Points

Try 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
Brodey Newman
10,962 Points

The 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
Larry Cousino
23,127 Points

Hi 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
Jeff McDivitt
23,970 Points

You 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!');  
}