Simulate rolling a dice using Math.random() . Your roll function should allow the caller to specify any
Fantastic news! We've Found the answer you've been seeking!
Question:
Simulate rolling a dice using Math.random(). Your roll function should allow the caller to specify any number of sides, but default to 6 if no side count is given: roll() assumes a 6 sided dice, returning a random number between 0 and 5, while roll(50) uses a 50 sided dice, and returns a random number between 0 and 49.
q2 - Givenr(radius) of a circle, calculate the area of a circle (A = * r * r).
q3 - Explain the following code in your own words, discussing how it uses JavaScript scope and closures.
function createFn(factor) {
return function(value) {
return value * factor;
};
}
let fn = createFn(10);
console.log(fn(6)); // What will this print and why?
Posted Date: