Aleksandra Chuprova
Aleksandra Chuprova

Reputation: 503

Expression of a multiple of 5

I think I have rather a simple question, I think...

I have this code

var resul = numCorrect+numIncorrect;
if (resul == 5){}

In place of 5 I want to have a multiple of 5 (5, 10, 15, 20) and so on. No 0!

I don't know how to express this in jquery. 5n doesn't work.

thanks in advance!

Upvotes: 0

Views: 425

Answers (2)

Edward Manda
Edward Manda

Reputation: 579

The modulus operator (%) gives the remainder after a number is divided is divided. Multiples of five will always give a modulus of 0. So you just have to check the modulus and exclude zero

if ((resul%5 == 0) && (resul !=0)) {
   //result is a multiple of 5
}

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use operator %:

if (resul && resul%5 == 0) {
   //multiple of 5
}

Upvotes: 4

Related Questions