Q:

Write a JavaScript program to find a value which is nearest to 100 from two different given integer values

0

 Write a JavaScript program to find a value which is nearest to 100 from two different given integer values. 

All Answers

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

function near_100(x, y) {
  if (x != y)
  {
  x1 = Math.abs(x - 100);
  y1 = Math.abs(y - 100);

  if (x1 < y1)
  {
    return x;
  }
  if (y1 < x1)
  {
    return y;
  }
  return 0;
  }
  else
    return false;
}

console.log(near_100(90, 89));
console.log(near_100(-90, -89));
console.log(near_100(90, 90));

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