Exercise Set 10

Exercise 1 of 6

Watch the logical operators video. Write a condition to match the message.

HTML

<button id="showMessageButton1">Show message</button>
<p id="messageParagraph1"></p>

JavaScript

var showMessageButton1 = document.getElementById("showMessageButton1");
var messageParagraph1 = document.getElementById("messageParagraph1");

var rich = true;
var famous = true;

showMessageButton1.addEventListener("click", showMessage1);

function showMessage1() {
  if (// your code will appear here) {
    messageParagraph1.innerHTML = "I am rich and famous";
  }
}

You must be signed in to type your code.

Exercise 2 of 6

Write a condition to match the message.

HTML

<button id="showMessageButton2">Show message</button>
<p id="messageParagraph2"></p>

JavaScript

var showMessageButton2 = document.getElementById("showMessageButton2");
var messageParagraph2 = document.getElementById("messageParagraph2");

var rich = false;
var famous = true;

showMessageButton2.addEventListener("click", showMessage2);

function showMessage2() {
  if (// your code will appear here) {
    messageParagraph2.innerHTML = "I am rich or famous";
  }
}

You must be signed in to type your code.

Exercise 3 of 6

Write a condition to match the message.

HTML

<button id="showMessageButton3">Show message</button>
<p id="messageParagraph3"></p>

JavaScript

var showMessageButton3 = document.getElementById("showMessageButton3");
var messageParagraph3 = document.getElementById("messageParagraph3");

var rich = true;
var famous = false;

showMessageButton3.addEventListener("click", showMessage3);

function showMessage3() {
  if (// your code will appear here) {
    messageParagraph3.innerHTML = "I am rich, but not famous";
  }
}

You must be signed in to type your code.

Exercise 4 of 6

Write a condition to match the message.

HTML

<button id="showMessageButton4">Show message</button>
<p id="messageParagraph4"></p>

JavaScript

var showMessageButton4 = document.getElementById("showMessageButton4");
var messageParagraph4 = document.getElementById("messageParagraph4");

var rich = false;
var famous = true;

showMessageButton4.addEventListener("click", showMessage4);

function showMessage4() {
  if (// your code will appear here) {
    messageParagraph4.innerHTML = "I am famous, but not rich";
  }
}

You must be signed in to type your code.

Exercise 5 of 6

Write a condition to match the message.

HTML

<button id="showMessageButton5">Show message</button>
<p id="messageParagraph5"></p>

JavaScript

var showMessageButton5 = document.getElementById("showMessageButton5");
var messageParagraph5 = document.getElementById("messageParagraph5");

var rich = false;
var famous = false;

showMessageButton5.addEventListener("click", showMessage5);

function showMessage5() {
  if (// your code will appear here) {
    messageParagraph5.innerHTML = "I am neither rich nor famous";
  }
}

You must be signed in to type your code.

Exercise 6 of 6

Write a condition to match the message.

HTML

<button id="showMessageButton6">Show message</button>
<p id="messageParagraph6"></p>

JavaScript

var showMessageButton6 = document.getElementById("showMessageButton6");
var messageParagraph6 = document.getElementById("messageParagraph6");

var rich = true;
var famous = false;

showMessageButton6.addEventListener("click", showMessage6);

function showMessage6() {
  if (// your code will appear here) {
    messageParagraph6.innerHTML = "I am either rich or famous, but not both";
  }
}

You must be signed in to type your code.