我想在答案正确时增加分数

时间:2019-07-31 11:05:30

标签: javascript

我正在做一个测验,我必须解决这些混乱的单词。一词解决后,一共有10个词,我想增加分数,最高分是10。我已经使用普通的If else语句尝试过,然后我使用了forloop尝试了,但是我的逻辑不正确。 >

我已经尝试过这种逻辑,但是没有奏效。

<script>
 $(".word").sortable({
   update: function(event, ui){
        /****** Upon every change in position of letter check if the updated word matches with the answer ******/
        var score = 0;

        var word = $(this).text().replace(/(\r\n|\n|\r)/gm, "").replace(/ /g,'');
        for(var i=0; i<10;i++){
        if(word === 'JOY'){
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.joy-win').show(500);
            $('.show-joy-btn').hide();
        }
        else if(word == 'BLISS')
        {   
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.bliss-win').show(500);
            $('.show-bliss-btn').hide();
        }
        else if(word === 'REGARD')
        {   
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.regard-win').show(500);
            $('.show-regard-btn').hide();
        }
        else if(word === 'THANKS')
        {   
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.thanks-win').show(500);
            $('.show-thanks-btn').hide();
        }
        else if(word === 'GRATITUDE')
        {
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.gratitude-win').show(500);
            $('.show-gratitude-btn').hide();
        }
        else if(word === 'PRAISE')
        {
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.praise-win').show(500);
            $('.show-praise-btn').hide();
        }
        else if(word === 'GOD')
        {
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.god-win').show(500);
            $('.show-god-btn').hide();
        }
        else if(word === 'ENOUGH')
        {
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.enough-win').show(500);
            $('.show-enough-btn').hide();
        }
        else if(word === 'BLESSINGS')
        {
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.blessings-win').show(500);
            $('.show-blessings-btn').hide();
        }
        else if(word === 'COMPARISON')
        {
            score++;
             $('.score').text(score);
            $(this).hide();
            $('.comparison-win').show(500);
            $('.show-comparison-btn').hide();
        }
        }
    }
});
</script>

1 个答案:

答案 0 :(得分:0)

您一直在覆盖柜台。 通过执行该功能,您的分数将始终被覆盖。

尝试将其放置在类似以下的地方:

var score = 0;
function(){
do some stuff...
}