Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Jeanne Boyarsky
• Liutauras Vilda
Sheriffs:
• Rob Spoor
• Bear Bibeault
• Tim Cooke
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Piet Souris
Bartenders:
• Frits Walraven
• Himai Minh

# rolling 2 dice

Greenhorn
Posts: 29
• Number of slices to send:
Optional 'thank-you' note:
In my last web development class, our professor showed us how to do a simple dice game with JavaScript and HTML. With this program, it would roll a single die, and then calculate how many times a given number was rolled out of a certain number of rolls.

For an assignment, he now wants us to take this same program, but to now have it done with 2 dice.

Here is some of my JavaScript and HTML that makes the program work:

How would I go about doing this for 2 dice?

author & internet detective
Posts: 40552
825
• Number of slices to send:
Optional 'thank-you' note:
Dan,
Take it slow. Can you do any of these (in order)

1) Create another variable like numberOfRolls2
2) Give it a random value.
3) Make the totals array bigger. How many outcomes are there now?
4) Point to a different spot in the array

Dan Czarnecki
Greenhorn
Posts: 29
• Number of slices to send:
Optional 'thank-you' note:
I actually figured it out.

I just figured out that I had to change the number of outcomes to 12, and then make a separate rollDice() function which I called 2 times.

Here's how I did it:

Jeanne Boyarsky
author & internet detective
Posts: 40552
825
• Number of slices to send:
Optional 'thank-you' note:
Dan,
Good job! Thanks for sharing that you got it.

 Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad? Thread Boost feature https://coderanch.com/t/674455/Thread-Boost-feature