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

Error in exercise but it runs

I typed the following code for the Javascript conditional code challenge :

var answer = prompt("What is the best programming language?"); if (answer.toUpperCase() === "JAVASCRIPT") { document.write("You are correct"); }

I get an error message from the course but the code seems to run correctly. Any hints at what I am doing wrong?

app.js
var answer = prompt("What is the best programming language?");
if (answer.toUpperCase === 'JAVASCRIPT') {
  alert("You are correct");
}
index.html
<!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>

3 Answers

Jeff Lemay
Jeff Lemay
14,268 Points

While your code is correct, the challenges look for very specific coding.

The task did not ask you to use the toUpperCase() function and wanted you to match the string "JavaScript".

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

Your answer is totally correct, but for the challenge all they want is for the conditional statement to be equal to "JavaScript"

if( answer === "JavaScript")

nothing more. the challenges are very strict and although your answer is the best choice, the challenge just want you to do the basics. I hope this helps.

Thanks Jeff & Jacob. the error I made originally was typing Javascript (I didn't capitalize the 's') The error I was receiving was that I wasn't using === for the conditional and that is when I started doing the other code experimentations.