0

I have four numbers 15 30 70 140. and "x", which can get any number, how to say if ()? that if x is equal to 15 30 70 140, then true, if not, then false.

const x =....;
if(x===?){....}else{....}
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79

2 Answers2

2

Use includes:

const nums = [15, 30, 70, 140];
const x = 70;
if (nums.includes(x)) console.log("Yay :)")
else console.log("Noo :(");

If the numbers are a space-separated string:

const nums = "15 30 70 140".split(" ").map(e => parseInt(e));
const x = 70;
if (nums.includes(x)) console.log("Yay :)")
else console.log("Noo :(");
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
0

You could use a switch and case statement:

// Get user input
var input = +prompt()

switch (input) {
  case 15:
  case 30:
  case 70:
  case 140:
    console.log(true)
    break;
  default:
    console.log(false)
    break;
}
Kobe
  • 6,226
  • 1
  • 14
  • 35