When I saw the answer of this question,I have a little question.
The answer said:
The random()
is const num = Math.floor(Math.random() * (max - min)) + min
. And the function call is let choice = array[random(0, array.length)]
.
But this can’t have the max one of the number, so the last name in the array will never display.
I thought it should change the random()
into const num = Math.floor(Math.random() * (max - min + 1) + min)
or change the function call into let choice = array[random(0, array.length + 1)]
can display the last name in the array.
Am I right? Or if I wrong, please tell me where, thank you very much.