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

JavaScript Basics - Stage 4: Making Decisions with Conditional Statements - Challenge Task 2 of 3

The code challenge doesn't seem to want to recognize my code. I ran it as it is through my sublime text and it worked fine in the browser. It is currently:

Challenge Task 2 of 3 :

Add a conditional statement that opens an alert dialog box with the message "You are correct" when the answer contains the string 'JavaScript'.

This is my Answer:

var answer = prompt("What is the best programming language?");
if (answer === 'Javascript') {
  alert("You are correct");
}

I keep getting the error:

Bummer! Did you use === to compare the answer with the string 'JavaScript' like this: answer==='JavaScript

Jesse Sudich
Jesse Sudich
11,398 Points

The error message should be updated to point out the capitalized S because otherwise it seems like it's all working perfectly.

10 Answers

Could it be that the 'S' isn't capitalized in JavaScript? I get errors like that a lot.

That was it, haha Thanks for the help. I guess I need to use my eagle eyes next time.

Patrick Butler
Patrick Butler
853 Points

This is an easy fix. It should be JavaScript and not Javascript

Sobin Sebastian
Sobin Sebastian
5,348 Points

the correct answer is var answer = prompt("What is the best programming language?"); if ( answer === "JavaScript" ) { alert("You are correct"); }

var answer=prompt('What is the best programming language?'); if(answer==='JavaScript'){ document.write("<p>" You are correct!</p>"); }

Justice Omorodion
PLUS
Justice Omorodion
Courses Plus Student 8,315 Points

var answer prompt ("What is the best programming language");

if (answer==='JavaScript') { alert("<p>You are correct!</p>"); }

Luiz Felipe Soares
Luiz Felipe Soares
13,840 Points

There is no need to use indexOf. If you want to accept variants of the answer use toUpperCase ou the toLower (don't forget to do the same with the other side of the comparison).

Don't forget we are using the strict equal operator, so it's going to check strictly how you write. And it should be a string (using quotes).

Cheers folks

Gary Thomas
Gary Thomas
6,893 Points

var answer = prompt ("What is the best programming language"); if (answer==='JavaScript') alert("You are correct");

Nic Henstridge
Nic Henstridge
974 Points

Caps was issue there but I always get problems when the code is perfect, must be a bug. I've given up now so just confirm it's correct and skip it. So much wasted time fecking about with code that is already correct....

Derek Etnyre
Derek Etnyre
20,822 Points

var answer = prompt("What is the best programming language?");

if(answer.indexOf("JavaScript") > -1) { alert("You are correct!"); }

Victor Gordian
Victor Gordian
4,656 Points

where does index come from?