Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Marvin Müller
Marvin Müller
8,884 Points

Coding challenge "making decisions with conditional statements" keeps telling me it's wrong despite the right output

Hey guys, So I'm stuck at the very last challenge of the conditional statements-part of the javascript basics course. Even though I get the expected output right , it keeps telling me that something is wrong. After I got it checked by the TH-Team , which told me everything is fine with the challenge itself, i wondered if you could help.

The programm wants you to check why it gets the message "Time to go to the theater" even thought it should get "It's Friday, but I don't have enough money to go out". So here is my 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 <= 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."); }

Even though I get the right message, I get this Bummer: 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.

anyone can tell me what I'm doing wrong? I changed the || operators in the first few if else loops to && , because it would always put out the "Time to go to the theater" message because the var today is set on Friday.

1 Answer

Steven Parker
Steven Parker
220,425 Points

You get the right output when you test on "Friday", but the code needs to give a different response for other days.

You're close, but you still have work to do on this line:

} else if ( money <= 10 || today !== 'Friday' ) {
  alert("It's Friday, but I don't have enough money to go out");

Paraphrasing the message: "It's Friday and I don't have enough money..." gives you a clue that there are two errors in the logic:

  • the conditions should be combined with the AND operator (&&) to make sure both are true
  • it should be testing that today is Friday instead of not Friday.
Marvin Müller
Marvin Müller
8,884 Points

I made it THANK YOU :). Yea I wasn't thinking about "if its not friday-thing".

Nice clues you gave me - now I could complete and get the badge :)

Steven Parker
Steven Parker
220,425 Points

:+1: Glad I could help. Happy coding!