function randomWholeNum()
{
return Math.floor(Math.random() * 10);
}
console.log(randomWholeNum());
console.log(“ans”,randomWholeNum());
function randomWholeNum()
{
return Math.floor(Math.random() * 10);
}
console.log(randomWholeNum());
console.log(“ans”,randomWholeNum());
Multiply the return value of Math.random() by 10.
Math.random returns a number between 0 and 1, which unless it returns 0 will be a decimal smaller than 1. Multiplying by 10 just moves the decimal point over one to the right, so instead of 0.7753337570110278 you have 7.753337570110278.
The asterisk sign is how you do multiplication in JS.