I am looking to get the results of the number of each number that shows in the results.
So if they request for 10 random numbers they can see their numbers and how many of each number there is. Somehow I need the [1, 2, 3, 4, 5, 2, 3, ] to pull in the results..
https://jsfiddle.net/by62764z/6/
function addFields() {
var number = document.getElementById("Rando").value;
var container = document.getElementById("container");
while (container.hasChildNodes()) {
container.removeChild(container.lastChild);
}
for (i = 0; i < number; i++) {
//move arr here
var Numbro = Math.floor((Math.random() * 10) + 1);
container.appendChild(document.createTextNode(" " + (Numbro)));
var input = document.createElement("input");
input.type = "number";
container.appendChild(document.createElement("br"));
}
}
var dataset = [1, 2, 3, 4, 5, 2, 3, ];
function findOccurrences(arr, val) {
var i, j,
count = 0;
for (i = 0, j = arr.length; i < j; i++) {
(arr[i] === val) && count++;
}
return count;
}
document.write("one " + findOccurrences(dataset, 1) + "<br>");
document.write("Two " + findOccurrences(dataset, 2) + "<br>");
document.write("Three " + findOccurrences(dataset, 3) + "<br>");
document.write("Four " + findOccurrences(dataset, 4) + "<br>");
document.write("Five " + findOccurrences(dataset, 5) + "<br>");
document.write("Six " + findOccurrences(dataset, 6) + "<br>");
document.write("Seven " + findOccurrences(dataset, 7) + "<br>");
document.write("Eight " + findOccurrences(dataset, 8) + "<br>");
document.write("Nine " + findOccurrences(dataset, 9) + "<br>");
document.write("Ten " + findOccurrences(dataset, 10) + "<br>");