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

mike o'shea
mike o'shea
9,917 Points

alert correct yet a bummer

money not equal to 9,today ===.Friday' alert comes up ok.Yet a bummer.?

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 ( 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 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

-- --
-- --
12,382 Points

Hi Mike,

What you would like the script to do:

  • Check if 'money' is (less than) a specific amount
  • Check if it is actually Friday as well
  • If 'money' is (less than) 9 AND it's actually Friday, alert "It's Friday, but I don't have enough money to go out"

So, let's start off by replacing the 'or' operators (||) with 'and' operators (&&), to make sure the script checks both the amount of money you have AND whether it's Friday or not. The default code says "if money is 'x' OR it is not Friday", so that's what we're fixing here.

Then, replace the 'is not' before all "Friday's", by turning !== into ===, because you want to make sure it's Friday as well after checking the amount of money.

On the last else if, check if money is (less than) 9: money <= 9. This else if will now check if 'money' has a value of 9 or less and it will know that today is Friday, and thus the output will be the alert saying "It's Friday, but I don't have enough money to go out".

That should do it.

Solution

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 this helps! :)

mike o'shea
mike o'shea
9,917 Points

Mace . many thanks for your swift reply. It will take a little while for me to get my head around this but if it solves it I'll let you know. Regard Mike.

mike o'shea
mike o'shea
9,917 Points

Thanks Mace ,worked. you have best answer from me. regards

-- --
-- --
12,382 Points

No problem! Glad I could help.