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 trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Super Conditional Challenge

This question is vague. Also, the script seems to require the use of the & (and) operator which hasn't been taught yet.

Also, I'm not sure what the values of today and money should be.

script.js
var money = 100;
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.");
}
index.html
<!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>

1 Answer

Steven Parker
Steven Parker
229,645 Points

You won't need the single ampersand operator for this challenge. But you might need the logical "and" operator, which is a double ampersand (&&).

The trick to this one is to look at how the conditions being tested relate to the messages that would be output. And when more than one test is being made at the same time there are different ways to combine them:

  • the AND operator ("&&") means both tests must be true
  • the OR operator ("||") means one test can be false if the other is true.

Also a test for equality ("===") or inequality ("!==") might need to be changed if it did not make sense for the message.

For example:

if (color === "blue") { alert("I sure am glad it is not blue!"); }

That code would not make sense. But if you changed the test operator to "!==" instead, it would.

So give the challenge another shot, and see if you can make each test (or test combination) make sense by substituting operators.