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 trialMicah Smith
5,510 PointsWhy isn't my script resolving challenge?!
In the javascript basics " making decisions with conditional statements -super conditional challenge" I am instructed to make the script print out " It's Friday but I don't have enough money to go out" and I am but the challenge is still saying I'm wrong.
var money = 9;
var today = 'Friday'
if ( money >= 100 || today === 'Tuesday' ) {
alert("Time to go to the theater");
} else if ( money >= 50 || today === 'Thursday' ) {
alert("Time for a movie and dinner");
} else if ( money >= 10 || today === 'Sunday' ) {
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.");
}
<!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
jason chan
31,009 PointsIt's testing you if you know how and or works?
It's && for and. When it's or. If either or is true something happens.
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.");
}
Jose Sanchez
7,849 PointsYou are on the right track but if you look at the operator that you are using to evaluate the if statement ----> || : means that only one of the statements need to be right in order for the alert underneath to be displayed. In the instructions they are stating that you need to have enough money + it needs to be friday for you to go to the movies. SO you will need to change || to && in order for it to actually get past the first couple of if statements.
jason chan
31,009 PointsMicah Smith no problem man. JS will come second nature soon enough. ;)
Micah Smith
5,510 PointsMicah Smith
5,510 PointsThanks a bunch Jason! I approached it all wrong lol but I understand now that both conditions needed to pass not just one or the other.