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 trialeva rios mb
Courses Plus Student 3,948 PointsAdding a conditional statement: My answer really seems correct yet it's continually marked wrong. Re-did it 3 times.
WHERE IS THE BUG?
var answer = prompt('What is the best programming language?');
if (answer.toUpperCase === 'JAVASCRIPT') { document.write('You are correct'); }
var answer = prompt('What is the best programming language?');
if (answer.toUpperCase === 'JAVASCRIPT') {
document.write('You are correct');
}
<!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>
1 Answer
Chyno Deluxe
16,936 PointsAlthough your answer would work in the real world. Code Challenges are a bit more strict in the answers they request.
You've added more to your code than the challenge has requested.
Task One asks that you declare the variable answer with a prompt to ask "What is the best programming language?" which you answered correctly.
However Task Two asks that you add a conditional to check if the answer is "JavaScript" and if so, alert "You are correct". The answer you provided changed the letter case of the answer given to uppercase and you wrote the answer to document rather than give an alert message.
var answer = prompt('What is the best programming language?');
if(answer === "JavaScript"){
alert("You are correct");
}
I hope this helps.
Nicole Bearup
2,860 PointsNicole Bearup
2,860 PointsI get the same problem when trying (answer === 'Javascript') or (answer.toUpperCase() === 'JAVASCRIPT'). Both result as incorrect.
Chyno Deluxe
16,936 PointsChyno Deluxe
16,936 PointsYes. That goes with my initial statement of the code challenges being very picky about the answers they want.
the correct spelling would be "JavaScript"