[英]How to increment score in Vanilla JS when a correct answer is typed into a textbox
[英]I want to increment the score when an answer is correct
我正在做一個測驗,我必須解決這些混亂的單詞。 一詞解決后,一共有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>
您一直在覆蓋櫃台。 通過執行該功能,您的分數將始終被覆蓋。
嘗試將其放置在類似以下的位置:
var score = 0;
function(){
do some stuff...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.