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 trialTy Shaw
Courses Plus Student 11,132 PointsJavaScript 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
10 Answers
John Sanchez
3,325 PointsCould it be that the 'S' isn't capitalized in JavaScript? I get errors like that a lot.
Ty Shaw
Courses Plus Student 11,132 PointsThat was it, haha Thanks for the help. I guess I need to use my eagle eyes next time.
Patrick Butler
853 PointsThis is an easy fix. It should be JavaScript and not Javascript
Sobin Sebastian
5,348 Pointsthe correct answer is var answer = prompt("What is the best programming language?"); if ( answer === "JavaScript" ) { alert("You are correct"); }
Enat Gebremariam
4,051 Pointsvar answer=prompt('What is the best programming language?'); if(answer==='JavaScript'){ document.write("<p>" You are correct!</p>"); }
Justice Omorodion
Courses Plus Student 8,315 Pointsvar answer prompt ("What is the best programming language");
if (answer==='JavaScript') { alert("<p>You are correct!</p>"); }
Luiz Felipe Soares
13,840 PointsThere 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
6,893 Pointsvar answer = prompt ("What is the best programming language"); if (answer==='JavaScript') alert("You are correct");
Nic Henstridge
974 PointsCaps 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
20,822 Pointsvar answer = prompt("What is the best programming language?");
if(answer.indexOf("JavaScript") > -1) { alert("You are correct!"); }
Victor Gordian
4,656 Pointswhere does index come from?
Jesse Sudich
11,398 PointsJesse Sudich
11,398 PointsThe error message should be updated to point out the capitalized S because otherwise it seems like it's all working perfectly.