I just made a button which gives me a random number from 1 to 57, and depending on the number given, I obtain a value associated to the number:
function coches() {
var x = Math.floor((Math.random() * 57) + 1);
if (x <= 3) {
document.getElementById("coche").innerHTML = "Audi " + x;
} else if (x <= 9) {
document.getElementById("coche").innerHTML = "BMW " + x;
} else if (x <= 17) {
document.getElementById("coche").innerHTML = "Mercedes " + x;
} else {
document.getElementById("coche").innerHTML = "Seat " + x;
}
}
<p id="coche"></p>
<input type="button" value="Click aqui!" onclick="coches()">
The problem is that now I need two things:
1.- The random number must depend on the probability of each car (I don't know If I explainded myself good, but I'll add an image above)
2.- When a random number appears, it should be removed from the list
Here is the image trying to explain it: