Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Shavonne Tate
Shavonne Tate
2,526 Points

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