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 trialjohn knight
Courses Plus Student 9,155 PointsQuestion
Why it says to me that I'm wrong?
var Question = prompt("what is the answer for 60/5?");
if (Question === "12) {
alert("that\'s right answer!.");
}
4 Answers
Marco Fregoso
501 PointsYou misspelled your code, inside your if conditional this should be your code:
var Question = prompt("what is the answer for 60/5?");
if (Question === "12") {
alert("that\'s right answer!.");
}
You just misspelled the "12" within quotes, you were missing one quote
Modesto Javier Espín Giménez
7,783 PointsAlso, although not a problem per se, remember that for styling purposes variables should go in camelCase.
Modesto Javier Espín Giménez
7,783 PointsAs far as I know, prompt() catches whatever you type as a string. If you want to compare it to the number 12 you either need to convert the string "12" to the number (use parseInt()) or use the operator "==" instead of "===", since with the latter you're also comparing the variable type.
Daniel Zeff
2,707 PointsJohn,
the input from the user is a string. Modesto pointed this out, but there are two ways to deal with the incoming data now attached to your variable. If you use equal to operator, "==", as opposed to the strictly equal to operator, "===" , then the string 12 is an accurate answer. If you feel like using strictly equal is the right way to do things, then using parseInt() will be needed to turn the string "12" into the number 12. This action allows the code to run and change the user input to a number, and therefore allows the needed strictness needed for "===" to be used.
john knight
Courses Plus Student 9,155 Pointsjohn knight
Courses Plus Student 9,155 Pointsso the number 12 must be a string, why it can't be a regular number without the quote marks?