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 trial6 Answers
Alex Heil
53,547 Pointshi 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 ;)
Erik McClintock
45,783 PointsKevin,
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
Jason Anello
Courses Plus Student 94,610 PointsAlso, 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
9,472 Pointsvar 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.");
}
David Sinclair
2,760 Pointsthanks for that.
Estephen Balaba
2,426 PointsThanks guys! Big help :)
Allan Jones
18,475 PointsThanks guys
Jean Carlos Batista
1,471 PointsThank You! :D
N A
10,296 PointsN A
10,296 Points~
John Mutch
6,962 PointsJohn Mutch
6,962 PointsGreat code just missed the ; at the end of the second var declaration.
jornemoonen
6,616 Pointsjornemoonen
6,616 PointsVery well explained, that makes sense. thank you!
Josue Zazueta
5,838 PointsJosue Zazueta
5,838 PointsI must remember to go block by block. thank!