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

Vedat Djabiroski
Vedat Djabiroski
1,891 Points

Super conditional chalenge

I tried diferent solutions but doesnt work. Any hints ?

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>

3 Answers

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Hey friend Vedat Djabiroski , in order to print 4th statement i,e "It's Friday, but I don't have enough money to go out" , you have to make the first three conditions wrong .
In order to make first three conditions wrong , just replace OR ( || ) operator with an AND ( &&) operator, and then first three condition will be evaluated to false and as a result 4th statement will be printed . Now there are lot of way's to print the 4th statement but as per the printing statement , it's saying - It's Friday, but I don't have enough money to go out"
So , just make today === 'Friday' && money === 9 and it's done :)
Here's is the code :

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

Hope it helps :)

Vedat Djabiroski
Vedat Djabiroski
1,891 Points

Thanks @Aakash Srivastav that worked, but i still wonder why my solution above doesnt worked , as you said the first 3 condition were wrong and the last one i made true, and then preview in the browser. also in the console it worked it printed the right message but still error and couldnt go foreward. thank you

Vedat Djabiroski
Vedat Djabiroski
1,891 Points

This works ok, it gives the right message alert but still an error... ' Bummer: Hmm. Looks like there is at least one logical OR operator -- that's the || symbols. Those test if just one of the conditions are true. '

Challenge Task 1 of 1

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

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

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Friend what you are doing wrong here is , question is asking you to make the first three conditions evaluate to false on the basis on price but you are making them false by making it another day i,e today !== 'Friday.
You have to work as per instruction , instruction is clearly saying you to make the first three conditions false on the value of money not day .
So , if it's Friday and the person have more than $ 100 , then he will go to theatre .
if it's Friday and the person have more than $ 50 but less than $100, then he will go to movie and dinner.
if it's Friday and the person have more than $ 10 but less than $50 , go for a movie
if it's Friday and the person have less than $10 , then "It's Friday, but I don't have enough money to go out" .

Steven Parker
Steven Parker
231,268 Points

The challenge error message is hinting that the "or" operators (||) might not be doing the intended job. Perhaps they need to be replaced with a different operator. :wink:

Vedat Djabiroski
Vedat Djabiroski
1,891 Points

ohh now i see ... my mistake was i didn't understand the error message.... thank you