Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions