如何保留赢或输并重置我的代码中的剩余变量?

时间:2017-05-20 17:57:51

标签: javascript jquery

如果我赢了比赛,我会输出以下代码输出输赢。我需要在输入/输掉后重置所有内容,但每次重置时都要保持我的赢/输数:

$("#mercury-planet").click(function() {
    var count = parseInt($("#counter").val());
    console.log(count);
    count += parseInt($("#mercuryHidden").val());
    $("#counter").val(count);
    if($("#counter").val() === randomNumber){
        wins++;
        $("#wins").html = "Wins: " + wins;
        //Win counter
        var winCount = parseInt($("#winCounter").val());
        winCount += parseInt($("#mercuryHidden").val());
        $("#winCounter").val(winCount + winCount + 1);//.val() -->needs to be updated
        alert("You won the game!!")
    }
    else if($("#counter").val() > randomNumber){
        losses++;
        $("#losses").html = "Losses: " + losses;
        //Loss counter
        var lossCount = parseInt($("#lossCounter").val());
        lossCount += parseInt($("#mercuryHidden").val());
        $("#lossCounter").val(lossCount - lossCount + 1);//.val() -->needs to be updated
        alert("You lost the game!!")
    }
})

0 个答案:

没有答案