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

Krzysztof Modrzewski
Krzysztof Modrzewski
1,378 Points

I don't udnerstand what it is wrong that I have alert('Oops! It looks like Task 1 is no longer passing')

What's more my code doesn't work and I don't know why:

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

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>
John Erickson
seal-mask
.a{fill-rule:evenodd;}techdegree
John Erickson
Full Stack JavaScript Techdegree Student 3,916 Points

Good day Krzysztof,

You mix a single quote and a double quote in your alert statement. You're unable to mix and match, you have to use one or the other.

alert("You are correct");

or

alert('You are correct");

2 Answers

Benjamin Barslev Nielsen
Benjamin Barslev Nielsen
18,958 Points

The problem is with:

alert('You are correct")

Note that you start the string by a single quote and try to end it with a double quote. You need to start and end the string with the same type of quote, i.e., both of the following are valid implementations:

alert('You are correct')
alert("You are correct")
Krzysztof Modrzewski
Krzysztof Modrzewski
1,378 Points

Benjamin thanks for catch that mistake :) But despite this I have an alert that Tas 1 is no longer passing...

Benjamin Barslev Nielsen
Benjamin Barslev Nielsen
18,958 Points

The reason that task 1 fails is because of the way your program is tested. Looking at the console output when checking the work in the challenge reveals the following typeError:

app.js:3 Uncaught TypeError: Cannot read property 'toUpperCase' of null

I guess they test your program with the value null as the answer, and since null isn't a string it does not have an toUpperCase property, which results in a TypeError, and therefore Task 1 also fails.

This however can be solved by checking that the type of answer is string:

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

With this code Task 1 passes, but task 2 does not. Treehouses tests specifically test that only "JavaScript" is accepted and therefore the code does not pass the test, since you also accept "javascript". Even though your solution probably is better than the one they ask for, it does not pass their tests to see if your solution is correct.

Krzysztof Modrzewski
Krzysztof Modrzewski
1,378 Points

Benjamin,

Thank You a lot :) You were right, when I had deleted .toUpperCase and had set ==='JavaScript' everything went great.

Best regards to You :)