Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let amount = parseInt(prompt("anna noppien määrä"));
- let score = parseInt(prompt("anna toivottu silmälukujen summa"));
- let hits = 0;
- const reps = 10000;
- function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min)) + min;}
- //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
- for (let i = 0; i < reps; i++){
- if (getRandomInt(1,6 * amount)== score){
- hits++;
- }
- }
- console.log((hits / reps) * 100 + "%");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement