This is usually called the module operator, but actually it finds the rest of an entire division, people confuse that because it’s very similar (you can see more details of this in the mgibsonbr response). He makes a division but instead of resulting in her value he results in the rest he would give in this division.
In the link above has a formula that approaches how the rest should be calculated in the hand, it is not accurate, it is just to give an idea).
the real usefulness of this mathematical symbol?
Forget the symbol, or treat it as a percentage (even less dollar that would be $). Treat it only as operator rest. In our context this is not a real mathematical symbol, since in mathematics this should result in a percentage calculation. It’s weird, but that’s what you could do. The percentage is easy to get, the rest not so much so they created an operator and used this symbol.
how I interpret this mathematical part when the dollar sign appears?
In the example how you want the rest of a division by 2 there are only two possible results, 0 or 1, therefore:
- if a number is even the rest is 0
- if it’s odd it’s 1.
Every integer divisible number will result in 0. This, too, is used to find out which primes or other formulas are.
Would you say that the rest is i of 2%? It will be correct?
You can say: "the rest of i divided by 2"
I made the code more streamlined:
function pares(x, y) {
for (let i = x; i <= y; i++) if (i % 2 === 0) console.log('Numero par: ' + i);
}
pares(32, 321);
I put in the Github for future reference.
Note that I simplified your code and solved a few things that could potentially cause problems and have more complex code, so pay close attention to it, in all characters.
And know that this case could be more simplified and performative:
function pares(x, y) {
for (let i = x; i <= y; i += 2) console.log('Numero par: ' + i);
}
pares(32, 321);
I put in the Github for future reference.
That symbol % is dollar?
– Sam
Ta more like a kkk interrogation. Now seriously, this symbol is Alberty percentage, but it has nothing to do with the symbol
%
used in mathematics.– JeanExtreme002
Good, kkk... Being read has its advantages.. Thank you friend
– Alberty Lucas