My mom works as a teacher, and I planned to surprise her with a random student picker for her 2nd-grade class. However, there seems to be an issue as it always selects the same student - Daniel. Despite setting up logging for the random numbers generated, I can't seem to figure out why Daniel is consistently chosen even when the random number doesn't correspond to his selection. What seemed like a simple task has turned into a puzzling problem. For context, my mother teaches in Denver where there is a diverse range of names among the 26 students in her class.
function studPick() {
var random = Math.random() * 100 / 3.84615384615;
var rand = Math.ceil(random*1)/1;
console.log("rand = " + rand + ".");
let student = "";
if (rand === 1) {
student = "Daniel";
}
else if (rand === 2) {
student = "Judge";
}
else if (rand === 3)
{
student = "Jonathan";
}
...
// Code for other student names omitted for brevity
...
else if (rand === 26) {
student = "Stella"
}
else {
alert("An error has occurred");
}
alert("Randomly picked student: " + student + ".")
}
Edit: I suspect that I may be redefining variables causing the issue. I will investigate further and remove this question if that resolves the problem.