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 trialAshok Oruganti
1,953 PointsSuper Conditional Challenge
I am getting a bummer message!
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< 9 ) {
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
Grace Kelly
33,990 PointsHi Ashok, you need to make a few changes to the conditional statements in order for them to execute properly:
var money = 9;
var today = 'Friday'
if ( money >= 100 && today === 'Friday' ) { //if i have 100 or more AND its friday
alert("Time to go to the theater");
} else if ( money >= 50 && today === 'Friday' ) { //if i have 50 or more AND its friday
alert("Time for a movie and dinner");
} else if ( money > 10 && today === 'Friday' ) { //if i have more than 10 AND its friday
alert("Time for a movie");
} else if ( today === 'Friday' ) { //if it's friday (and i have 10 or less)
alert("It's Friday, but I don't have enough money to go out");
} else { //if it's not friday
alert("This isn't Friday. I need to stay home.");
}
The reason why "||" needs to be replaced is because even though you don't have enough money to go to the theater (you have 9 when you need at least 100) the code will still execute because it's friday. But by using "&&" it will check that both conditions are met and if they are not, the code will move on the the next conditional statement.
Hope this helps!!
Jason Anders
Treehouse Moderator 145,860 PointsThe problem is you are using || which is the "OR" symbol. So when the code runs through the first conditional, it will return "True" because it is "Friday."
Change the || to &&
Also you should have >= 10 and <= 9. Otherwise, it's all good.
Hope that helps. Jason
danheffernan
10,004 PointsYou're using OR || in all your conditional statements, which means only one of the conditions needs to be met for the code block to run. Try making sure both conditions within the conditional statements evaluate to true in order for the code block to run. IE: if (condition1 AND condition2) {do something}
Ashok Oruganti
1,953 PointsAshok Oruganti
1,953 Pointsi took the condition today===friday || money<9 still not working