JSFiddle - React, Tailwind, and code Playground

HTML

<div>
    <p id="msg8"></p>
    <input type="button" id="findStudentBtn" value="Find Student!"></input>
</div>

JavaScript

findStudentBtn.onclick = findStudent;



function findStudent() {
    var studArray = ["John","Daniel","Hans","Lars","Tom","Amanda","Jane","Sarah"] //1-8
    for (i=0; i<3; i++) {
        if (i=1) {
            var randomStud1 = studArray[Math.floor(studArray.length * Math.random())];
            msg8.innerHTML += randomStud1 + ", ";
        }
        if (i=2) {
            var randomStud2 = studArray[Math.floor(studArray.length * Math.random())];
            msg8.innerHTML += randomStud2 + ", ";
        }
        if (i=3) {
            var randomStud3 = studArray[Math.floor(studArray.length * Math.random())];
            msg8.innerHTML += randomStud3 + ", ";
        }
        
        if (randomStud1 == randomStud2 || randomStud2 == randomStud3 || randomStud1 == randomStud3){
            ms8.innerHTML = "";
            findStudent();
        } 
    }
}