![](/img/trans.png)
[英]How to disable Cognito user after exceeding the unsuccessful login attempts
[英]After user attempts answer, how to reset gameboard for next selection (jquery)
我在玩危險游戲。 我能夠讓用戶選擇一個正方形,問題出現並帶有輸入框,他們單擊“提交”,然后將答案與正確答案進行比較。 如果正確,則說出並在總分中加分;如果錯誤,則說出並從總分中扣除。 但隨后游戲停滯了。 我無法弄清楚如何為選擇下一個問題做好准備。
這是第一個問題的js代碼。 如果您需要更多代碼,請讓我知道(我不希望這個問題很混亂)。 可能有一個簡單的解決方案,所以如果您想知道“為什么不只使用______ ,,”,答案是因為我是菜鳥,而且我不知道該怎么做。 提前非常感謝您。
codepen: http ://codepen.io/Nplagma/pen/XNerRw
$(document).ready(function() {
$(".question").hide();
var score = 0;
$(".well").hover(function() {
$(this).addClass('blue');
}, function() {
$(this).removeClass('blue');
});
$("#A1").click(function() {
var questionValue = $(this).data("questionvalue");
$(".question").show();
$('<h4>The \"MVP\" quarterback whose team is 14-6 when he doesn’t play.</h4>').appendTo('.question');
$('#submit').click(function() {
$("#answer").on('input')
var answer = $('#answer').val(); //what does this mean in words?
if
(answer == "Tom Brady" || answer == "Brady" || answer == "brady" || answer == "tom brady") {
$('.question').replaceWith('<h3>omg you\'re so smart</h3>') //using h3 because it'll be unique, but there must be a better way
score += questionValue;
$(".score").text("$" + score);
}
else
{
$('.question').replaceWith('<h3>could NOT have been more wrong</h3>');
score -= questionValue;
$(".score").text("$" + score);
}
});
});
僅供參考。 您選擇的方法可能不是完成任務的最佳方法。 您的用戶可以輕松地檢查代碼以找到問題的答案。 一種“更好”的方法是將所有數據(即問題和答案)存儲在數據庫中,並使用ajax訪問該數據。 然后,您還需要學習后端語言和SQL。
您還使用了不同的狀態。 當這變得更加復雜時,您會發現控制它們並跟蹤所有內容很痛苦。 這就是前端框架真正發揮作用的地方。 我建議您檢查一下。 如今有很多。 React,Angular,Meteor,Vue,Backbone等。將它們檢出並選擇對您最有意義的一種。 (
但是,如果您僅使此應用程序學習javascript更好。 繼續您的方法:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.