0

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;
            }       
        }
4
  • 1
    for (attempt > 3 && studentID == localStorage.studentID) you mean if? Commented Oct 6, 2016 at 6:06
  • Looks like you meant a while loop. Commented Oct 6, 2016 at 6:06
  • You want to use a while, not a for, when you have multiple conditions like that instead of just a counter. Commented Oct 6, 2016 at 6:06
  • 1
    Your code looks half-baked... Commented Oct 6, 2016 at 6:08

1 Answer 1

1

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;
    }       
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that, but my local storage is not storing attempt, and my gradeTest function is working.
That is not the question and the code in your gradeTest function is not in the code you provided. Read the documentation on localStorage and how to call functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.