When working with if statements in JavaScript, I've had to write out some rather lengthy conditionals. Here is an example one where three numbers have to be 0-100:
if ((num1 > 100 || num1 < 0) || (num2 > 100 || num2 < 0) ||
(num3 > 100 || num3 < 0)) {
return 'One of these is invalid';
} else {
return 'Ok, we are good.';
}
I don't know if it's possible to shorten this up, I tried searching for similar questions, but couldn't find anything. But is it possible to do something like this in JavaScript? (or if not in JavaScript, is it possible to do it in other languages?)
if (num1, num2, num3 > 100 || num1, num2, num3 < 0) {
return 'One of these is invalid';
} else {
return 'Ok, we are good.';
}
Aucun commentaire:
Enregistrer un commentaire