javascript – How to limit attemps in the quiz? Need to store number of attempts in localstorage

Here’s my code in javascript, code calculates the score and shows result on the result.html page.

Then using localStorage I need to limit number of attemps identifying the user by his ID .
If attemps are less than 3 I need to give a link of the quizpage on result page and suggest to try again. If there was already 3 attemps i don’t give the link to quiz and prevent user to do quiz again.

    "use strict"

function saveResult(firstn,sutid,score){
    if(typeof(Storage)!=="undefined"){
        localStorage.setItem("firstn",firstn);
        localStorage.setItem("sutid",sutid);
        localStorage.setItem("score",score);
    }
}

    function getResult(){
        if(typeof(Storage)!=="undefined"){
            if(localStorage.getItem("sutid")!==null){
                var firstn=document.getElementById("firstn");
                firstn.textContent=localStorage.getItem("firstn");

                var sutid=document.getElementById("sutid");
                sutid.textContent=localStorage.getItem("sutid");

                var score=document.getElementById("score");
                score.value=localStorage.getItem("score");
            }
        }
    }

function validate(){
    var errMsg="";
    var result=true;
    var score=0;

    //declaring variables for info and q1,4,5
    var sutid=document.getElementById("sutid").value;
    var q1=document.getElementById("proglang").value.trim();
    var q4=document.getElementById("list").value;
    var q5=document.getElementById("percent").value;
    var firstn=document.getElementById("firstn").value;
    var lastn=document.getElementById("lastn").value;

    //check first name
    if (firstn==""){
        errMsg+="Please enter your name.<br>";
        result=false;
    }

    //check for last name
    if (lastn==""){
        errMsg+="Please enter your last name.<br>";
        result=false;
    }



    //check student id
    if (sutid==""){
        errMsg+="Please enter your students id.<br>";
        result=false;
    }

    //question 1
    if (q1==""){
        errMsg+="PLease answer the question 1.<br>";
        result=false;
    }
    else if (q1.match(/dart/i)){ //we use i to prevent case sensitivity
        score+=10;
    }

    //question 2
    var m17=document.getElementById("m17").checked;
    var m19=document.getElementById("m19").checked;
    var mr17=document.getElementById("mr17").checked;

    if (!(m17 || m19 || mr17)){
        errMsg+="Please answer the question 2.<br>";
        result=false;
    }

    else if (m17){
        score+=10;
    }

    //question 3
    var arg=document.getElementById("arg").checked;
    var vrb=document.getElementById("vrb").checked;
    var rear=document.getElementById("rear").checked;

    if (!(arg || vrb || rear)){
        errMsg+="Please answer the question 3.<br>";
        result=false;
    }
    //question has 2 correct answers
    else if (arg && vrb){
        score+=10;
    }

    //question 4
    if (q4==""){
        errMsg+="PLease answer the question 4.<br>";
        result=false;
    }

    else if (q4=="setState"){
        score+=10;
    }

    //question 5
    if (q5==""){
        errMsg=+"Please answer the question 5.<br>";
        result=false;
    }

    else if (q5==90){
        score+=10;
    }

    //check error messages 
    if (errMsg!=""){
        document.getElementById("err").innerHTML=errMsg;
    }
    else if (score==0){
        document.getElementById("err").innerHTML="Score is zero. please try again";
        result=false;
    }
    else { //if no errors and score>0, send data to localStorage 
        saveResult(firstn,sutid,score);
    }
    return result;
}

function init(){
    if (document.getElementById("quizPage")){ //quiz page init
        document.getElementById("quizForm").onsubmit=validate;
    }
    else if (document.getElementById("resultPage")){ //result page init
        getResult();
    }
}
window.onload=init;