Question: in Java script: Array / Function: Rolling Die Simulation See the sample code with comments. Copy the sample code to your solution. Complete the requirements
in Java script: ArrayFunction: Rolling Die Simulation
See the sample code with comments.
Copy the sample code to your solution. Complete the requirements in the code template.
Overview
Simulate or rolls number of rolls chosen randomly of a die and display statistics.
High Leve Tasks
Your code will perform the following tasks:
Populate an array simulating or rolls
Create a function that returns the number of times a roll occurred
Input: A digit between
Return: A single number. Count the number of times that the digit was rolled
Display output
A simple header
Result statistics see output and requirements below
Output
Your numbers will vary as the results are random
Output Format Requirements
A header with your last name and number of rolls in the simulation
Details for each outcome Actual and expected occurrences and relative frequencies
Round relative frequency to digits after the decimal
Use the format below.
qVerOutput.png
Code Template Copy this to VS Code and complete the requirements
Simulate rolling a die
Array to store result of each roll
const roll ;
Write code to populate the array with the outcome of the rolls.
Determine Number of rolls A random number of rolls or
HINT: Generate a random number between and multiply it by
Populate the array use a loop:
For each roll, generate a random number between and add it to the array.
When complete, you will have an array of or elements.
Each element will have a value between
YOUR CODE HERE
Function Return the number of occurrences of a roll
Write a function per the following requirements:
Input: A digit between assume valid input
Return: A single number. Count the number of occurrences of the digit in the roll array
No other tasks are performed by the function.
Failure to meet these requirements, even if the output is correct, will
result in an incorrect solution
HINT
Many ways to do this, one is to loop through the array counting the number of occurrences
OTHERMISCOPTIONAL
The rolls array is global; However, if you want to make your function more generic,
you may use it as an input parameter.
YOUR CODE HERE
Display the results to the console
Generate a header as follows:
YourLastName Rolling Die Simulation Statistics XXXX Rolls
Note: XXXX will be either or
eg Asher's Rolling Die Simulation Statistics Rolls
YOUR CODE HERE
Write a loop to display the statistics for each possible outcome
Counts Actual and Expected. Relative frequency Actual and expected
See requirements document for output format.
Note:
Counts
Actual Use the function you created to compute the count of an outcome
Expected Total rolls
Relative frequency
Actual Actual count from your function total number of rolls
Expected
YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
