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

1 Expert Approved Answer
Step: 1 Unlock

Simulating Dice Rolling with ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!