How to know how many numbers exist from x to y? [closed]

-4

For example, from 0 to 60. Obviously I know how many numbers exist, but what I do is know how to make my algorithm find out this mathematically.

    
asked by anonymous 21.08.2017 / 16:28

1 answer

7

function quantosNumerosExistem(x, y) {
    return Math.abs(y - x) + 1;
}

document.write(
    " De 3 até 10: " + quantosNumerosExistem(3, 10) + "<br>" +
    " De 0 até 60: " + quantosNumerosExistem(0, 60) + "<br>" +
    " De -2 até 2: " + quantosNumerosExistem(-2, 2) + "<br>" +
    " De 0 até 0: " + quantosNumerosExistem(0, 0) + "<br>" +
    " De 0 até 1: " + quantosNumerosExistem(0, 1) + "<br>" +
    " De -10 até -8: " + quantosNumerosExistem(-10, -8)
);
   
    
21.08.2017 / 16:33