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 Super Conditional Challenge

Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Don't understand why is wrong

var money = 9; var today = 'Friday'

if ( money >= 100 || today === 'Sunday' ) { alert("Time to go to the theater");
} else if ( money >= 50 || today === 'Thursday' ) { alert("Time for a movie and dinner");
} else if ( money > 10 || today === 'Monday' ) { alert("Time for a movie");
} else if ( money > 10 || today === 'Friday' ) { alert("It's Friday, but I don't have enough money to go out");
} else { alert("This isn't Friday. I need to stay home."); }

script.js
var money = 9;
var today = 'Friday'

if ( money >= 100 || today === 'Sunday' ) {
  alert("Time to go to the theater");    
} else if ( money >= 50 || today === 'Thursday' ) {
  alert("Time for a movie and dinner");    
} else if ( money > 10 || today === 'Monday' ) {
  alert("Time for a movie");   
} else if ( money > 10 || today === 'Friday' ) {
  alert("It's Friday, but I don't have enough money to go out");   
} else {
  alert("This isn't Friday. I need to stay home.");
}
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="script.js"></script>
</body>
</html>

4 Answers

Julian Gutierrez
Julian Gutierrez
19,201 Points

In the code today is Friday, we initialized that near the top, if you look closely at the conditionals they all have

|| today === 'Friday'

So the first conditional is checking to see if money is greater than or equal to 100 OR if today is equal to Friday. Since money equals 9 the first part of the conditional is false. But since today is equal to Friday and we are using the OR operator "||" the whole conditional evaluates to true which should be incorrect.

We need each conditional to only evaluate to true if each side of the logical operator is true and we do that with "&&" (without the quotes).

Julian Gutierrez
Julian Gutierrez
19,201 Points

This challenge needs you to debug the code without changing the day. This part of the code should be the same for all the conditionals.

today === 'Friday'
Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Thank you Julian Gutierrez

Very Kind! Didn't understand the challenge needs.

Still I don't get the solution... I will study harder.

Can you give me a little advise?

Thank you

Cesare

Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Thank you Julian

I understood!

I tried to change || with && in a first time but I mad something else wrong, so I tried to change variables messing around with the code.

Thank you for your help

Cesare