7.4  Java Script - Logic Operators 

Index Code Tester

OBJECTIVE

DISCUSSION

Boolean Operators 

if (x == 4 && y <= 2) { 
   alert("x equals 4 and y is less than or equal to 2");
   };
if (sName == "bob" || sName == "Bob" || sName == "BOB") {
   alert("Name is Bob")
   };
if (x >= 3.14 && x < 3.142) {
    alert("That looks like PI");
}

EXERCISES

1.  Given the following:  x = 5, y = 10, z = 20, sName = "bo".  Review each of the following statements and determine if they will evaluate to True or False:

  1. (x < 10)
  2. (x < 10 && y < 10)
  3. (2*x <= y)
  4. !(z != x || z != x)
  5. (x < 5 || y < 5 || z < 5) 
  6. (x*y > y*z && y <= z)
  7. (sName = "bo" || sName = "Bo")
  8. (sName != "x")
  9. ((true && false) || (true || false))

2.  Look up "truth table" on the Internet.  What is a "truth table"?

3.  Create a "boolean operation calculator".  This calculator will allow the user to enter true or false in two textboxes, select an operator (AND or OR), and then display the result of the operation.   

4.  Repeat #3 but use four textboxes so that the user can determine the results of expressions such as "(true && false) || (true && true)".  You may need to include a feature that will permit the user to indicate which comparison to make first.

5.  Create a truth table for #4.

LINKS AND HELP
Search for "Boolean Operators".