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{....}
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{....}
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 :(");
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;
}