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 trialLuis Paulino
Courses Plus Student 1,779 PointsHow do I get the else clause to work?
I can't get the last else clause to work. I'm not sure if I have to fix the else if statments or what
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> 8 || 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
Inge L
30,058 PointsThe goal is "It's Friday, but I don't have enough money to go out".
Think on this way, you have to satisfy it is Friday and you already satisfied with today === 'Friday', next you have to satisfy that you don't have enough money, you have less than some amount of money you are questioning is it true or false. And you need to question both('Friday' and money) statements is it true, not just one or another.
Jae Min Kweon
4,695 PointsYou can try to go through the conditional statement with your given variables.
I am seeing that you have var money = 9 and var today = 'Friday'. I also see that you have or operator (||) in your conditions.
Remember that if there is an or operation with two boolean evaluation, only one of them have to be true for the entire condition to be true. In other words, in order to pass through all the conditions, you would have to make sure that all the booleans within the conditions of if and else if are false.
At the moment your day value is 'Friday', so it would get caught on the if statement and just run that block of code. So first you would probably have to fix that (change the day to another day). Following that change, your money value is 9, which will get caught as true in the last else if statement and run that. Thus, you will have to change the money value as well.
If I recall this lesson correctly though, I think you will probably have to suffice both conditions to carry out the action that is alerted by the code. In this case you would have to change the operator to the and operator (&&). Even after that you will still get caught on the last else if statement, since it suffices both parameters. In order to avoid that you would have to change either variables to make sure that at least one of the boolean evaluations return a false.