window.onload = () =>{
    document.getElementById("yourscore").innerText = localStorage.getItem("playerScore");
    document.getElementById("computerscore").innerText = localStorage.getItem("computerScore");
};

function play(choice) {
    let playerScore = localStorage.getItem("playerScore") == null ? 0 : Number(localStorage.getItem("playerScore"));
    let computerScore = Number(localStorage.getItem("computerScore")) == NaN ? 0 : Number(localStorage.getItem("computerScore"));
    choice = Number(choice)
    let num = Math.floor(Math.random() * 3);
    let computerChoice = makeittext(num);
    document.getElementById("computerchoice").innerText = computerChoice;
    document.getElementById("yourchoice").innerText = makeittext(choice);
    
    if(num == choice){
        document.getElementById("winnertext").innerText = "It is a TIE!";
    }
    else if(num == 0 && choice == 1){
        document.getElementById("winnertext").innerText = "YOU WON!";
        playerScore += 1;
    }
    else if(choice == 0 && num == 1){
        document.getElementById("winnertext").innerText = "The COMPUTER WON!";
        computerScore += 1;
    } 
    else if(num == 0 && choice == 2){
        document.getElementById("winnertext").innerText = "The COMPUTER WON!";
        computerScore += 1;
    }
    else if(num == 2 && choice == 0){
        document.getElementById("winnertext").innerText = "YOU WON!";
        playerScore += 1;
    }
    else if(num == 1 && choice == 2){
        document.getElementById("winnertext").innerText = "YOU WON!";
        playerScore += 1;
    }
    else if(num == 2 && choice == 1){
        document.getElementById("winnertext").innerText = "The COMPUTER WON!";
        computerScore += 1;
    }

    document.getElementById("yourscore").innerText = playerScore;
    document.getElementById("computerscore").innerText = computerScore;

    localStorage.setItem("playerScore", playerScore)
    localStorage.setItem("computerScore", computerScore)
}

function computerChoise() {
    let num = Math.floor(Math.random() * 3);
    return makeittext(num);
}
function makeittext(num){
    let res = "";
    switch (num) {
        case 0:
            res = "Rock";
            break;
        case 1:
            res = "Paper";
            break;
        case 2:
            res = "Scissors";
            break;
    }
    return res;
}
