Khoo Wing Hang Khoo Wing Hang - 2 months ago 17
Javascript Question

SyntaxError: missing ; after for-loop initializer

showing errors like missing ; after for-loop. Thanks for helping.

function checkAttempt(){
var studentID = document.getElementById("studentID").value;
var attempt = 0;

for (attempt < 3 && studentID == localStorage.studentID){
gradeTest;
attempt = attempt + 1;
localStorage.attempt = attempt;
}
}

Answer

Replace for with while:

function checkAttempt(){
    var studentID = document.getElementById("studentID").value;
    var attempt = 0;

    while (attempt < 3 && studentID == localStorage.studentID{
        gradeTest;
        attempt = attempt + 1;
        localStorage.attempt = attempt;
    }       
}