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 trialmoath alqutoob
2,450 PointsWhat is the correct answer
I CANT PASS THIS
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' ) {
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>
2 Answers
Robert Nellums
Courses Plus Student 2,640 PointsI agree that you have your condition OR || mixed up with your condition AND &&, but you also have typos and logical errors.
On the last else if, you state that if the day is NOT Friday, then you say "It is Friday, but I do not have enough money...". Logically, that isn't right.
Study the code below as I believe this is the correct way. I do not know what the assignment wants, but I can tell by your code what you are after.
Be sure to close your variable declarations with a semicolon.
Hope this helps!
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.");
}
Gabriel Ward
20,222 PointsHi Moath,
I think you will need to change the || sign to && in the first three conditions.
|| is the equivalent of or, and tests whether either of the conditions inside the brackets is true or not.
For example, for the statement
if ( money >= 100 || today === 'Friday' )
to evaluate to true, only one of the conditions has to be true.
If you change || to &&, so you have,
if ( money >= 100 && today === 'Friday' )
then both conditions have to be true for the statement to evaluate to true.
Also, I think
else if ( today !== 'Friday' )
Should be
else if ( today === 'Friday' )
Gina Scalpone
21,330 PointsGina Scalpone
21,330 PointsThis is the correct answer!
It can be simplified slightly--because the previous if-else statements have already failed, you don't need to specify in the last else-if statement that the variable money is less than 10:
Jeff Jacobson-Swartfager
15,419 PointsJeff Jacobson-Swartfager
15,419 PointsMoath, this is your answer!