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

Where am I going wrong in line 8 of this challenge?

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 !== 9 && 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>

2 Answers

Shouldn't you check if money is less than or equal to 10? You check if its Friday and you don't have 9 bucks, what about 8,7,6,... bucks?

And all your OR statements (||) should be AND statements (&&)? (If it's Friday AND you have more than 10 bucks, then go to theater (and dinner)

Got it, Thank you for help Jonathan

The parameters are that 1. you must have enough money AND 2. it must be Friday. The first thing is to change all of the OR (||) statements to AND (&&).

Then, in order to get to the 2nd "else if" clause, the first two will need to return FALSE.

money > 10 (This is FALSE because 10 is greater than 9 and money is a const variable, which cannot be reassigned.) money >= 50 (This is FALSE because 50 is greater than 9 and money is a const variable, which cannot be reassigned.)

In order for the 2nd "else if" clause to be TRUE and the correct alert to appear, what would need to be TRUE is that "it is Friday but I don't have enough money." In this case, you can leave the "money" variable out of the string (0) BUT make sure the "today" variable returns TRUE --- that it is Friday. To do this, you make sure the operation is === (IS) instead of !== (IS NOT).

HERE IS THE FINAL CODE: 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 ( 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."); }