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

N A
N A
10,296 Points

Broken Challenge? Script not working.

~

6 Answers

Alex Heil
Alex Heil
53,547 Points

hi Kevin Lesht , this challenge can be a little bit tricky because there's not only one problem to fix. I'll try to walk you through and hope that's more beneficial than simply pasting the right answer (but I will put it at the end ;) )

So, first let's check the question: 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"

this tells us that we should end at the last else if-statement, so that's the place we need to get to.

as the conditions start form top to bottom, let's have a closer look: 1) condition 1 you already changed the OR to AND - great, done!

2) now it jumps to the next condition "time for a movie and dinner" - there I can still see the OR statement - therefore the program stops here and we don't get to our desired output - means we should change the OR to AND here as well

3) same as nr. 2 - we're now at this check and there's also an OR that we need to change as otherwise we don't get to the next code block.

4) that's the line we care about - and you already changed the OR to the AND statement - great.

so I bet if you fix the lines 2 and 3 you'll pass just fine ;)

here's the full code at the end:

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' && money < 10 ) {
  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 that helps and have a nice day ;)

Great code just missed the ; at the end of the second var declaration.

Very well explained, that makes sense. thank you!

Josue Zazueta
Josue Zazueta
5,838 Points

I must remember to go block by block. thank!

Erik McClintock
Erik McClintock
45,783 Points

Kevin,

This one is odd, but it is not broken. It wants you to replace all of the || operators with && to make the conditionals make more sense.

Erik

Also, you have to be careful with what you did for the last else if:

} else if ( today === 'Friday' && money < 10 ) {

You only need to check that it's Friday. It's not necessary to add on a money check but if you do it should be money <= 10

As it stands right now, if it was Friday and you had exactly $10, it would fall through to the else and say that it's not Friday.

Ayman Omer
Ayman Omer
9,472 Points

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' && money < 10 ) { 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 guys! Big help :)