Operators - Exercise 2

Question 1: Check a Valid Temperature

Return true when a temperature is at least the minimum and at most the maximum, inclusive.

Expected output: true (print this with console.log)

javascript

function isTemperatureInRange(temperature, min, max) {
  // Write your solution here
}

console.log(isTemperatureInRange(18, 15, 25));

Question 2: Allow Either Payment Method

Return true if either cash or card is accepted. Both arguments are booleans.

Expected output: true (print this with console.log)

javascript

function acceptsEitherPayment(cash, card) {
  // Write your solution here
}

console.log(acceptsEitherPayment(false, true));

Question 3: Reverse a Door State

Return true when the supplied isOpen boolean is false, and false otherwise.

Expected output: false (print this with console.log)

javascript

function doorIsClosed(isOpen) {
  // Write your solution here
}

console.log(doorIsClosed(true));

Question 4: Choose a Display Name

Use || to return the supplied name, or "Guest" when the name is falsy.

Expected output: "Guest" (print this with console.log)

javascript

function chooseDisplayName(name) {
  // Write your solution here
}

console.log(chooseDisplayName(""));

Question 5: Keep a Zero Volume

Use ?? to return the supplied volume or 50 only when it is null or undefined.

Expected output: 0 (print this with console.log)

javascript

function defaultAudioVolume(volume) {
  // Write your solution here
}

console.log(defaultAudioVolume(0));

Question 6: Choose a Shipping Label

Return "free" when the total is at least 50 and "paid" otherwise, using a conditional operator.

Expected output: "free" (print this with console.log)

javascript

function shippingChargeLabel(total) {
  // Write your solution here
}

console.log(shippingChargeLabel(55));

Question 7: Compare Numeric Text Loosely

Use == to compare the supplied number and numeric string. Return the boolean result.

Expected output: true (print this with console.log)

javascript

function looselyCompareNumericText(number, text) {
  // Write your solution here
}

console.log(looselyCompareNumericText(7, "7"));

Question 8: Detect a Changed Setting

Return true when the two setting values are not strictly equal.

Expected output: true (print this with console.log)

javascript

function settingHasChanged(before, after) {
  // Write your solution here
}

console.log(settingHasChanged(1, "1"));

Question 9: Negate a Temperature Change

Return the arithmetic negation of the supplied number using the unary minus operator.

Expected output: -8 (print this with console.log)

javascript

function negateTemperatureChange(change) {
  // Write your solution here
}

console.log(negateTemperatureChange(8));

Question 10: Convert a Numeric Input

Use unary plus to convert a numeric string to a number.

Expected output: 3.5 (print this with console.log)

javascript

function convertNumericInput(text) {
  // Write your solution here
}

console.log(convertNumericInput("3.5"));