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
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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Simulating Dice Rolling with ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started