Q:

Write a JavaScript program to check from two given integers whether one of them is 8 or their sum or difference is 8

0

Write a JavaScript program to check from two given integers whether one of them is 8 or their sum or difference is 8.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function check8(x, y) {
  if (x == 8 || y == 8) {
    return true;
  }

  if (x + y == 8 || Math.abs(x - y) == 8)
  {
    return true;
  }

  return false;
}

console.log(check8(7, 8));
console.log(check8(16, 8));
console.log(check8(24, 32));
console.log(check8(17, 18));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now