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 Making Decisions in Your Code with Conditional Statements Use Multiple Conditions

Yonara Acevedo
Yonara Acevedo
1,356 Points

Multiple conditions

I have been working on this exercise for a while, for my looks correct. The correct message is displayed, but I got this error message: It looks like there is at least one logical OR operator (that's the || symbols). Those test if just one of the conditions is true.

The instructions for the challenge are: "Something's wrong with this script. The value in the variable money is 9. But if you preview this script, the browser displays the message "Time to go to the theater." Fix this script so that it correctly tests the money and today variables and prints the proper alert message: "It's Friday, but I don't have enough money to go out."

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

if ( money > 10 && today === 'Friday' ) {
  alert("Time to go to the theater.");    
} else if ( money >= 50 && today === 'Friday' ) {
  alert("Time for a movie and dinner.");    
} 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 charset="utf-8">
    <title>JavaScript Basics</title>
  </head>
  <body>
    <script src="script.js"></script>
  </body>
</html>

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 38,004 Points

Hi Yonara

} 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.");
}

So you have an OR so if either statement is correct it is going to print today is Friday. money is always going to be less than equal to 10 since above you tested for money greater than 10 above (remember if else statement end after finding a true statement). So definitely need an AND. Now since our first statement says "It's Friday, ..." do we want to test for money NOT EQUAL to 'Friday'? I think that needs to be EQUAL to 'Friday'.

Hope this helps and helps you understand. Keep at it!

Yonara Acevedo
Yonara Acevedo
1,356 Points

Thanks for your help! It was a hard one for me. I got it!!!