Sunday, April 18, 2021

20. Write a JavaScript program to check from two given integers, if one is positive and one is negative.

20. Write a JavaScript program to check from two given integers, if one is positive and one is negative.

function positive_negative(x, y)
{
  if ((x < 0 && y > 0) || x > 0 && y < 0) 
  {
    return true;
  }
  else 
  {
    return false;
  }
}
console.log(positive_negative(2, 2));
console.log(positive_negative(-2, 2));
console.log(positive_negative(2, -2));
console.log(positive_negative(-2, -2));

No comments: