WDI Fundamentals

WDI Fundamentals Unit 8

Your Turn Your Turn

Logical Operators and Booleans Exercise


  1. Write the code to perform the actions listed below in the "JavaScript" panel in the JS Bin editor.
  2. If you don't see the JS Bin below, please refresh the page.
  3. Click "Run" to run the code in the "Console" panel.
  4. After clicking "Run", to check variable values, type the variable name in the "Console" panel on the right and hit enter/return.

JS Bin on jsbin.com

Let's get started!

  1. In the "JavaScript" panel, declare a variable flavor and assign it the value to "chocolate".

    Note: After declaring (creating) each variable, be sure to check to make sure you've done things correctly by hitting the "Run" button and then typing the variable name (flavor; in this case) in the "Console" panel and hitting the return/enter key to check its value. You'll want to do this after each step.

  2. Create a variable numberScoops and assign it the value 3.
  3. Create a variable outsideTemperature and assign it the value 75.
  4. Create a variable price and assign it the value 3.5.
  5. Create a variable buyIceCream and set it equal to an expression that incorporates the following:
    • price is less than or equal to 2.5 OR
    • outsideTemperature is greater than or equal to 70 AND
    • flavor is equal to "chocolate" AND
    • numberScoops is greater than 1
  6. After hitting "Run", type buyIceCream; into the console and hit the return/enter key to see whether or not you should buy that delicious chocolate ice cream cone under the given conditions.

Stuck? Check out the solutions for assistance.

Next up we'll look at how we can use the operators we learned in this lesson to add logic to our programs. Here we go!