The browser storage localStorage is not available. Either your browser does not support it or you have disabled it or the maximum memory size is exceeded. Without localStorage your solutions will not be stored.
Random numbers
Math.random()
returns a pseudo-random number between 0 (inclusive) and 1 (exclusive).
let x = Math.random();
x
could, for example, get the value 0.6206372241429993
.
Each call of Math.random()
generates a new random number.
The numbers are equally distributed between 0 and 1. They are called pseudo-random numbers,
because they look random but are still calculated.
If you want to get random numbers in another range or with a different distribution,
you have to transform the numbers generated by Math.random()
adequately.
This should be practiced now.Exercise
Write a function
dice
that returns like a dice a random number between 1 and 6.
+ Solution
function dice() {
let x = Math.random() * 6;
return Math.ceil(x);
}