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

What is wrong with comparsion op

!== is 'not equal to', but still i cannot print the right statement, why?

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>

Hi Ammar, could you mark the best answer if one of us helped to find the solution? Thank you!

2 Answers

The problem is that the conditional statement is using "||" which represents "or" and in order to check if both arguments are true you need to use "&&". Also the last else if should be === not !== because it is Friday but you have no money.

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

Thanks, but we only needed to fix 'It's Friday, but i don't have enough money to go out'. why we changed other statements?

The reason we need to change the other statements is because the way it is originally set up it will never reach "It's Friday, but I don't have enough money to go out" because first it checks the first if statement.

if ( money >= 100 || today === 'Friday' ) {
  alert("Time to go to the theater");    
}

This statement will pass and return the alert because it is saying "if I have at least $100 or its Friday alert 'time to go to the theater'". since it is in fact Friday this statement passes so it can not reach the following "else if" statements. The same goes for the following 2 "else if" statements because it uses "||" which states that 1 of the 2 conditions needs to be true for the statement to pass. For the program to function correctly the first 3 statements need to use the "&&" which means "and" to require that both arguments pass rather than the "||" which means "or" and requires only one of the arguments to pass. I hope that helps.

Hi Ammar,

You need to put a semicolon after 'Friday':

var today = 'Friday';

OMG, how can i be so blind. I am laughing on my stupidity right now.