Sunday, April 18, 2021

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

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

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));

No comments: