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
Monica Anderson
3,621 PointsI am trying to do a conditional statement in JavaScript and it is not working.
Here is the code: var answer = prompt("What is the best programming language?"); if (answer === "JavaScript"); { alert("You are correct"); } else { alert("JavaScript is the best language!") }
thanks so much Monika
3 Answers
Steven Parker
243,656 Points It looks like you have a stray semicolon (;) between the end of the if condition and the opening brace of the code block.
Monica Anderson
3,621 Pointsthanks!
Sam Okasha
10,343 PointsA few things in your code to fix:
1) The semi-colon after the if statement closing parentheses. 2) You need to convert the answer in the prompt to uppercase in your if statement so no matter which lettercase is used, typing in 'javascript' will work.
Here's what finished code would look like:
var answer = prompt('What is the best programming language?');
if (answer.toUpperCase() === 'JAVASCRIPT') { alert('You are correct'); } else
{ alert('JavaScript is the best language!') }