Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone help me come up with a JavaScipt code: The frequency of each possible roll (2 to 12 inclusive) must be updated, and the
Can someone help me come up with a JavaScipt code:
- The frequency of each possible roll (2 to 12 inclusive) must be updated, and the frequency as a percentage of the total number of accumulated rolls must be updated.
This is my current code to roll dice
Help will be very appreciated been stuck for over a week
let count = 0; function throwdice() { let rand1 = Math.ceil( x: Math.random() *6); let rand2 = Math.ceil( x: Math.random() *6); let result = rand2 + rand1; //change the image show by string concatenation document.getElementById( elementld: "image1").src = "images/dice" + rand1 + ".png"; document.getElementById( elementid: "image2").src = "images/dice" + rand2 + ".png"; //set alt image let sideAlt = ["roll:1", "roll:2", "roll:3", "roll:4", "roll:5", "roll:6"] document.getElementById( elementld: "image1").alt = sideAlt[rand1-1] document.getElementById( elementld: "image2").alt = sideAlt[rand2-1] arrayResult[indexPos] = rand1 + rand2; indexPos++; addToArray(); die Interval(); document.getElementById( elementld: "pRolled").innerHTML = "You rolled " + result; count++; document.getElementById( elementld: "pTotalRolls").innerHTML = "My statistics for a total of rolls:" + count; } let count = 0; function throwdice() { let rand1 = Math.ceil( x: Math.random() *6); let rand2 = Math.ceil( x: Math.random() *6); let result = rand2 + rand1; //change the image show by string concatenation document.getElementById( elementld: "image1").src = "images/dice" + rand1 + ".png"; document.getElementById( elementid: "image2").src = "images/dice" + rand2 + ".png"; //set alt image let sideAlt = ["roll:1", "roll:2", "roll:3", "roll:4", "roll:5", "roll:6"] document.getElementById( elementld: "image1").alt = sideAlt[rand1-1] document.getElementById( elementld: "image2").alt = sideAlt[rand2-1] arrayResult[indexPos] = rand1 + rand2; indexPos++; addToArray(); die Interval(); document.getElementById( elementld: "pRolled").innerHTML = "You rolled " + result; count++; document.getElementById( elementld: "pTotalRolls").innerHTML = "My statistics for a total of rolls:" + count; }Step by Step Solution
There are 3 Steps involved in it
Step: 1
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