Commit 70b4ab9f authored by Nurasyl's avatar Nurasyl

add total arr val

parent f3587919
function getRandomNumber() { return Math.round(Math.random() * 99) };
function showResult(arr) {
alert(
`
Group 0 - 9: ${arr[0]}
Group 10 - 19: ${arr[1]}
Group 20 - 29: ${arr[2]}
Group 30 - 39: ${arr[3]}
Group 40 - 49: ${arr[4]}
Group 50 - 59: ${arr[5]}
Group 60 - 69: ${arr[6]}
Group 70 - 79: ${arr[7]}
Group 80 - 89: ${arr[8]}
Group 90 - 99: ${arr[9]}
`
);
};
// function getRandomNumber() { return Math.round(Math.random() * 99) };
// function showResult(arr) {
// alert(
// `
// Group 0 - 9: ${arr[0]}
// Group 10 - 19: ${arr[1]}
// Group 20 - 29: ${arr[2]}
// Group 30 - 39: ${arr[3]}
// Group 40 - 49: ${arr[4]}
// Group 50 - 59: ${arr[5]}
// Group 60 - 69: ${arr[6]}
// Group 70 - 79: ${arr[7]}
// Group 80 - 89: ${arr[8]}
// Group 90 - 99: ${arr[9]}
// `
// );
// };
// function counterGroup(arr, num) {
// if(num >= 0 && num <= 9) {
// arr[0]++;
// } else if(num >= 10 && num <= 19) {
// arr[1]++;
// } else if(num >= 20 && num <= 29) {
// arr[2]++;
// } else if(num >= 30 && num <= 39) {
// arr[3]++;
// } else if(num >= 40 && num <= 49) {
// arr[4]++;
// } else if(num >= 50 && num <= 59) {
// arr[5]++;
// } else if(num >= 60 && num <= 69) {
// arr[6]++;
// } else if(num >= 70 && num <= 79) {
// arr[7]++;
// } else if(num >= 80 && num <= 89) {
// arr[8]++;
// } else if(num >= 90 && num <= 99) {
// arr[9]++;
// };
// };
// const groupArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
// for(let i = 0; i <= 100000; i++) {
// counterGroup(groupArr, getRandomNumber());
// };
// showResult(groupArr);
function counterGroup(arr, num) {
if(num >= 0 && num <= 9) {
arr[0]++;
} else if(num >= 10 && num <= 19) {
arr[1]++;
} else if(num >= 20 && num <= 29) {
arr[2]++;
} else if(num >= 30 && num <= 39) {
arr[3]++;
} else if(num >= 40 && num <= 49) {
arr[4]++;
} else if(num >= 50 && num <= 59) {
arr[5]++;
} else if(num >= 60 && num <= 69) {
arr[6]++;
} else if(num >= 70 && num <= 79) {
arr[7]++;
} else if(num >= 80 && num <= 89) {
arr[8]++;
} else if(num >= 90 && num <= 99) {
arr[9]++;
};
};
const groupArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const groupArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let total = 0;
for(let i = 0; i <= 100000; i++) {
counterGroup(groupArr, getRandomNumber());
for(let i = 0; i < groupArr.length; i++) {
total += groupArr[i];
};
showResult(groupArr);
\ No newline at end of file
console.log(total / groupArr.length);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment