I am new to JavaScript and I would like to get three random elements out of my array, which need to be different. I already managed to get three different elements, then I tried to take one element only once via the split method. But apparently this doesn't really work, there are probably a lot of mistakes since this is one of my first scripts. Also it sometimes says "undefined".
HTML:
<span id="tot1"></span>, <span id="tot2"> und </span> und <span id="tot3"></span>
Javascript:
function getNumber() {
random = Math.floor(Math.random() * students.length);
students.splice(random,1);
return random;
}
students = new Array("Paul", "Jan", "Fabian D.", "Fabian K.", "Lennard",
"Robin", "Angelique", "Joyce", "Sarah", "Ajlin",
"Enes", "Leon", "Boran", "Joshua")
getNumber();
tot1 = students[random];
getNumber();
tot2 = students[random];
getNumber();
tot3 = students[random];
document.getElementById('tot1').innerHTML = tot1;
document.getElementById('tot2').innerHTML = tot2;
document.getElementById('tot3').innerHTML = tot3;