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

Brooke Guy
Brooke Guy
8,179 Points

STUMPED

Someone help...banging my head on the wall

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

if ( money >= 100 || 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("Time for a movie");   
} 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.");
}
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>

2 Answers

Stipe Stipic
Stipe Stipic
17,520 Points

You need to change the || (OR) in && (AND) , and in the last else if use the identical compare === here the code:

if ( money >= 100 && 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("Time for a movie");   
} 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.");
}
Steven Parker
Steven Parker
231,269 Points

Try not to remove any operators from the code, though you will need to change some.

The trick to this one is to look at how the conditions being tested relate to the messages that would be output. And when more than one test is being made at the same time there are different ways to combine them:

  • the AND operator ("&&") means both tests must be true
  • the OR operator ("||") means one test can be false if the other is true.

Also a test for equality ("===") or inequality ("!==") might need to be changed if it did not make sense for the message.

For example:

if (color === "blue") { alert{"I sure am glad it is not blue!"): }

That code would not make sense. But if you changed the test operator to "!==" instead, it would.

So give the challenge another shot, and see if you can make each test (or test combination) make sense by substituting operators.