I want to check if a value is a multiple of a certain number, for example, multiples of 10, but I also want to be able to change it to whatever I want.
if (directWinner == 10){
}
I want to check if a value is a multiple of a certain number, for example, multiples of 10, but I also want to be able to change it to whatever I want.
if (directWinner == 10){
}
Share
Improve this question
edited Mar 25, 2013 at 15:02
Emil Ivanov
37.6k12 gold badges76 silver badges90 bronze badges
asked Mar 25, 2013 at 14:58
user1937021user1937021
10.8k25 gold badges85 silver badges150 bronze badges
3
- 2 This does have absolutely nothing to do with jQuery. – Bergi Commented Mar 25, 2013 at 15:00
- 5 Amazing. Staggering. doxdesk.com/img/updates/20091116-so-large.gif – Matt Ball Commented Mar 25, 2013 at 15:00
- -1 all the answers, not enough jQuery. – BinaryTox1n Commented Mar 25, 2013 at 15:04
3 Answers
Reset to default 18You'd use the modulus operator for that :
if (directWinner % 10 === 0){
directWinner = 20;
}
Added a small dose of jQuery for no good reason at all ?
$.modu = function(check, against) {
return check % against === 0;
}
if ( $.modu(directWinner, 10) ) {
directWinner = 20;
}
You'd use the modulo operator %
for that:
var certainNumber = 10;
if (directWinner % certainNumber === 0) {
// directWinner is a multiple of certainNumber
}
Use the modulo operator (assuming positive integers) :
if (directWinner % 10 === 0) {
...
}