- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
好的,在我的测验中,我使用等于 0 的变量从 if 语句和 else if 语句增加。一个变量应该在你做对问题时增加,另一个变量应该在你做错问题时增加。每当你答错一道题时,如果你答对了下一题,它就不再增加正确的变量。如果你得到一个不正确的变量,它不会增加不正确的变量。如果您摆脱第二个 .btn 点击监听器,它出于某种原因不会发布问题。我不想摆脱它,让它成为一个工作的听众。
$(document).ready(function(){
var quiz = [
{
question:"How boring is this quiz?",
choices:["kinda","very","Too boring","Very fun"],
answer: "kinda"
},
{
question:"What color is Mace Windu's Lightsaber?",
choices:["purple", "blue", "green", "yellow"],
answer: "purple"
},
{
question:"Who purchased ATI in 2006?",
choices:['Asus', 'NZXT', 'AMD', 'HyperX'],
answer: "AMD"
},
{
question:"What is the rest of this Star Wars characters name? Jar Jar...",
choices:["Smith", "Ranks", "Banks", "Johnson"],
answer: "Banks"
},
{
question:"What color is C3PO?",
choices:["Golden", "Blue", "Orange", "Teal"],
answer: "Golden"
},
{
question:"What is missing from the quote? These are not the ____ you're looking for.",
choices:["Shirts", "Movies", "Computers", "Droids"],
answer: "Droids"
},
{
question:"What is the correct version of the characters name that starts with Jabba?",
choices:["jabba The Small", "Jabba Williams", "Jabba The Hutt", "Jabba The Clean"],
answer: "Jabba The Hutt"
},
{
question:"Which answer has the correct spelling of a characters name?",
choices:["Fiin", "Finn", "Fiinn", "Fin"],
answer: "Finn"
},
{
question:"Which of the following is not a character in Star Wars?",
choices:["Luke Skywalker", "Finn", "R2D2", "Morgan Skywalker"],
answer: "Morgan Skywalker"
},
{
question:"Is the word yes an answer for this question?",
choices:["yes", "This is the wrong answer", "This is the wrong answer", "This is the wrong answer"],
answer: "yes"
}
];
var title = document.getElementById('questionname');
var questions = document.getElementById('questions');
var i = 0;
var correct = 0;
var incorrect = -1;
var quizQuestion = 0;
var answer = quiz[i].answer;
var btn = document.getElementById('new');
var selections = [];
//$('.score').html("Correct:" + amount);
$('.btn').click(function() {
console.log('made it here')
event.preventDefault();
console.log(selections)
//for (var i = 0; i < quiz.length; i++){
/*console.log($("input:checked").val(),'$("input:checked").val()');
console.log(quiz[quizQuestion].answer,'quiz[i].answer');
console.log(amount,'amount');*/
if($("input:checked").val() === quiz[quizQuestion].answer){
correct++;
$('.score').html("Correct:" + correct + " Incorrect:" + incorrect);
console.log(correct);
quizQuestion++;
fillQuestion(quizQuestion);
}
else if ($("input:checked").val() !== quiz[quizQuestion].answer) {
incorrect++;
}
//}
});
//fillQuestion(0);
$('.btn').click(function() {
event.preventDefault();
fillQuestion(i);
i++;
/*if($("input:checked").val() == answer){
correct.push("l");
$('.score').html("Correct:" + amount);
console.log("Yo");
}
//if(i>quiz.length -1) {
//i=0;
//}
//fillQuestion(i);
//i++;
//console.log("Hi.");
//$('.score').html("Correct:" + amount);*/
});
function fillQuestion(qNum){
var specificQuestion = quiz[i];
title.innerText = specificQuestion.question;
questions.innerHTML = "";
for(key in specificQuestion.choices){
var btnQuestion = "question"+i+"_choice";
var questionText = specificQuestion.choices[key];
questions.appendChild(createQuestion(btnQuestion,questionText)
);
}
}
/*for (var i = 0; i < choices.length; i++) {
$(title).text(quiz[0].question);
$('questions').append('<label><input type="radio" name="usernames" value="' + choices[i] + '" /> ' + choices[i] + '</label>');
}*/
function createQuestion(name, questionText) {
var e = document.createElement('li');
var questionHTML = '<input type="radio" value="'+questionText+'" name="' + name + '"';
questionHTML += '/>';
questionHTML += questionText;
e.innerHTML = questionHTML;
return e;
}
});
html, body {
margin:0px;
padding:0px;
background-color:#FFFAF0;
}
.container{
width:960px;
margin:0px;
padding:0px;
position:absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.title{
font-family:lato;
font-size:20px;
position:relative;
left:350px;
}
.question{
width: 300px;
height: 300px;
position:absolute;
top:50%;
left:50%;
-ms-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
display:inline-block;
background-color:#008080;
padding:20px;
margin:30px;
border-radius:5%;
}
ul{
list-style:none;
}
.btn{
width:75px;
height:50px;
top:200px;
left:100px;
position:relative;
background-color:olive;
}
.hint{
font-size:10px;
position:relative;
left:200px;
top:100px;
margin:0;
}
.score{
margin:0px;
padding:5px;
outline:solid;
outline-color:black;
display:inline-block;
position:relative;
top:40px;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lato">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="quiz.js"></script>
<link rel="stylesheet" type="text/css" href="animate.css">
<link rel="stylesheet" type="text/css" href="question1.css">
</head>
<body>
<div class="container">
<h2 class="title" id="questionname"></h2>
<div class="question" id="questionsarea">
<ul id="questions"></ul>
<ul class="answer">
</ul>
<div class="score"></div>
</div>
</div>
<button id="new" class="btn" value="Next">Next</button>
<p class="hint"></p>
</div>
</body>
</html>
最佳答案
您遇到了一些问题。不需要第二个 onclick
事件。可以删除一些开头未使用的变量。
当到达最后一个问题时,我添加了一个停止以防止超限问题。
if(quizQuestion >= quiz.length - 1) { return false; }
我添加了两个变量用于比较,没有它们我遇到了问题。 (可能是这个环境。)
var choice = $("input:checked").val();
var answer = quiz[quizQuestion].answer;
我将 quizQuestion
修复为在将其作为参数传递之前进行预递增。
fillQuestion(++quizQuestion);
fillQuestion()
函数中还有一些其他更改,jQuery 选择器不正确。
试试这个:
$(document).ready(function(){
var quiz = [
{
question:"How boring is this quiz?",
choices:["kinda","very","Too boring","Very fun"],
answer: "kinda"
},
{
question:"What color is Mace Windu's Lightsaber?",
choices:["purple", "blue", "green", "yellow"],
answer: "purple"
},
{
question:"Who purchased ATI in 2006?",
choices:['Asus', 'NZXT', 'AMD', 'HyperX'],
answer: "AMD"
},
{
question:"What is the rest of this Star Wars characters name? Jar Jar...",
choices:["Smith", "Ranks", "Banks", "Johnson"],
answer: "Banks"
},
{
question:"What color is C3PO?",
choices:["Golden", "Blue", "Orange", "Teal"],
answer: "Golden"
},
{
question:"What is missing from the quote? These are not the ____ you're looking for.",
choices:["Shirts", "Movies", "Computers", "Droids"],
answer: "Droids"
},
{
question:"What is the correct version of the characters name that starts with Jabba?",
choices:["jabba The Small", "Jabba Williams", "Jabba The Hutt", "Jabba The Clean"],
answer: "Jabba The Hutt"
},
{
question:"Which answer has the correct spelling of a characters name?",
choices:["Fiin", "Finn", "Fiinn", "Fin"],
answer: "Finn"
},
{
question:"Which of the following is not a character in Star Wars?",
choices:["Luke Skywalker", "Finn", "R2D2", "Morgan Skywalker"],
answer: "Morgan Skywalker"
},
{
question:"Is the word yes an answer for this question?",
choices:["yes", "This is the wrong answer", "This is the wrong answer", "This is the wrong answer"],
answer: "yes"
}
];
var title = document.getElementById('questionname');
var questions = document.getElementById('questions');
var i = 0;
var correct = 0;
var incorrect = -1;
var quizQuestion = 0;
var answer = quiz[i].answer;
var btn = document.getElementById('new');
var selections = [];
$('.btn').click(function(event) {
if(quizQuestion >= quiz.length - 1) { return false; }
event.preventDefault();
var choice = $("input:checked").val();
var answer = quiz[quizQuestion].answer;
fillQuestion(quizQuestion);
if(choice === answer){
correct++;
}
else if (choice !== answer) {
incorrect++;
}
$('.score').html("Correct:" + correct + " Incorrect:" + incorrect);
fillQuestion(++quizQuestion);
});
function fillQuestion(qNum){
console.log('in fillQuestion' + qNum);
var specificQuestion = quiz[qNum];
$('#questionname').html(specificQuestion.question);
questions.innerHTML = "";
for(key in specificQuestion.choices){
var btnQuestion = "question"+key+"_choice";
var questionText = specificQuestion.choices[key];
questions.appendChild(createQuestion(btnQuestion,questionText));
}
}
function createQuestion(name, questionText) {
var e = document.createElement('li');
var questionHTML = '<input type="radio" value="'+questionText+'" name="' + name + '"';
questionHTML += '/>';
questionHTML += questionText;
e.innerHTML = questionHTML;
return e;
}
});
html, body {
margin:0px;
padding:0px;
background-color:#FFFAF0;
}
.container{
width:960px;
margin:0px;
padding:0px;
position:absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.title{
font-family:lato;
font-size:20px;
position:relative;
left:350px;
}
.question{
width: 300px;
height: 300px;
position:absolute;
top:50%;
left:50%;
-ms-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
display:inline-block;
background-color:#008080;
padding:20px;
margin:30px;
border-radius:5%;
}
ul{
list-style:none;
}
.btn{
width:75px;
height:50px;
top:200px;
left:100px;
position:relative;
background-color:olive;
}
.hint{
font-size:10px;
position:relative;
left:200px;
top:100px;
margin:0;
}
.score{
margin:0px;
padding:5px;
outline:solid;
outline-color:black;
display:inline-block;
position:relative;
top:40px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="animate.css">
<link rel="stylesheet" type="text/css" href="question1.css">
</head>
<body>
<div class="container">
<h2 class="title" id="questionname"></h2>
<div class="question" id="questionsarea">
<ul id="questions"></ul>
<ul class="answer">
</ul>
<div class="score"></div>
</div>
</div>
<button id="new" class="btn" value="Next">Next</button>
<p class="hint"></p>
</div>
关于javascript - 来自变量的实时测验分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40838107/
直接从 Python 代码运行 pylint 时,我似乎无法获得任何返回值。从命令行运行它会生成一个漂亮的报告,在底部有一个总结分数。 我已经尝试将“Run”的返回值放入一个变量中,并获取它的“rep
我是 Python 新手,正在尝试学习单词检测。我有一个带有单词的数据框 sharina['transcript'] Out[25]: 0 thank you for calling my
http://jsfiddle.net/q8P7Y/ 我在最后显示最终分数时遇到问题,有很多方法可以做到这一点,但我不确定什么是最好的。 正如你所看到的,下一个按钮只是 div 的显示/隐藏,而不是页
我使用滑动 slider 并有计数器分数。它计数很好,但我需要计数 =(所有幻灯片 - 1)。例如,如果我有 20 张幻灯片,我想显示总数 19。有什么办法可以做到这一点吗?我使用他们网站上的常规 j
我使用滑动 slider 并有计数器分数。它计数很好,但我需要计数 =(所有幻灯片 - 1)。例如,如果我有 20 张幻灯片,我想显示总数 19。有什么办法可以做到这一点吗?我使用他们网站上的常规 j
我试图在按下按钮时添加分数,分数显示在 JTextField 中,但是当按下按钮时,分数会添加,它显示为 0。我有一个存储分数的整数字段 private int score=0; yesButton
我可以在选项(单选按钮)随机播放之前计算分数/分数,如下面的代码所示。在Collection.shuffle()之前,选项是固定的,因为 CorrectChoice将始终分配给c2单选按钮。那么我可以
我在这里的代码只能得到87%的代码,因为“带有非正参数的加法参数什么也没做。我该如何解决呢?我尝试了更多的方法,但是我什至无法解决此错误在同学的帮助下 说明是: 对于此分配,您将创建一个存储分数的类。
昨天,我尝试以一种方式执行此操作...今天我尝试另一种方式,但仍然卡住了。我必须找到一种使用整数除法和取模来做到这一点的方法。这是我的代码,后面是错误消息。 public int evaluateFr
我这里有一些特殊字符: http://209.141.56.244/test/char.php 但是当我在这里通过 ajax 抓取这个文件时,它们显示为 back ?标记: http://209.14
我得到了一张图表 G与 n顶点,标记自 1至 n (2 a_1 -> a_2 -> ... a_k -> n A然后将占据 1 的所有“子节点”节点, a_1 , ... a_x (其中 x = ce
我有一个看起来像这样的 mongodb 集合: db.scores.insert({"name": "Bob", value: 96.3, timeStamp:'2010-9-27 9:32:00'}
我试图更好地了解 lucene 如何对我的搜索进行评分,以便我可以对我的搜索配置或文档内容进行必要的调整。 以下是分数明细的一部分。 产品: 0.34472802 = queryWeight,
在我网站上用户生成的帖子下,我有一个类似亚马逊的评级系统: Was this review helpful to you: Yes | No 如果有投票,我会在该行上方显示结果,如下所示:
对于我的项目,我需要找出哪些搜索结果被视为“良好”匹配。目前,分数因查询而异,因此需要以某种方式对它们进行标准化。标准化分数将允许选择高于给定阈值的结果。 我为 Lucene 找到了几个解决方案: h
我有一个由 57 个变量组成的数据文件。由于测量水平不均匀,我想将其中的大约 12 个转换为 z 分数。我查找了互联网资源和帮助文件。一个互联网资源建议我需要 Rbasic 包(不存在)。我使用了 s
我对 SOLR 核心运行查询并使用过滤器限制结果例如 fq: {!frange l=0.7 }query($q)。我知道 SOLR 分数不有绝对意义,但是0.7(只是一个例子)是计算出来的基于用户输入
我想找到不同的方法来解决我遇到的现实生活问题:想象一下进行一场比赛或一场游戏,在此期间用户收集积分。您必须构建一个查询来显示具有最佳“n”分数的用户列表。 我举一个例子来澄清。假设这是用户表,其中包含
我有很多 wiki 页面,我想训练一个分类器,看看是否可以通过一些特征(包括段落的位置和段落的 lucene 分数)来确定重点搜索的位置。我尝试将每个段落视为一个文档,这使我能够获得每个段落的 luc
我是 R 编程新手,在使用一些基本代码时遇到问题。 我有一个包含以下列的数据框:条件(因子)、用户(因子)和灵敏度(int)。对于每个用户有 20 个敏感项。我需要为每个用户创建一个具有标准化敏感度分
我是一名优秀的程序员,十分优秀!