javascript 询问并评分问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 询问并评分问题相关的知识,希望对你有一定的参考价值。
//function print(message) {
// var outputDiv = document.getElementById('output');
// outputDiv.innerHTML = message;
//// document.write(message);
//}
//
//var questions = [
// ['How old is Mark?', '50'],
// ['How many states are in the US?', '50'],
// ['What is 10 times 5?', '50']
//];
//
//var numCorrect = 0;
//var answer;
//var HTML;
//
//for (var i=0; i<questions.length; i++){
// answer = prompt(questions[i][0]);
// if (answer === questions[i][1]){
// numCorrect++;
// questions[i].push(1);
// } else {
// questions[i].push(0);
// }
//}
//
//HTML = "You got " + numCorrect + " question(s) right."
//HTML += '<h2>You got these questions correct:</h2>';
//HTML += listCorrect(questions);
//HTML += '<h2>You got these questions wrong:</h2>';
//HTML += listWrong(questions);
//print(HTML);
//
//function listCorrect(arr){
// var listHTML = '';
// for (var i=0; i<questions.length; i++){
// if (questions[i][2] === 1){
// listHTML += (i+1) + '. ' + questions[i][0] + '<br>';
// }
// }
// return listHTML;
//}
//
//function listWrong(arr){
// var listHTML = '';
// for (var i=0; i<questions.length; i++){
// if (questions[i][2] !== 1){
// listHTML += (i+1) + '. ' + questions[i][0] + '<br>';
// }
// }
// return listHTML;
//}
//Alternatively
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
// document.write(message);
}
var questions = [
['How old is Mark?', 50],
['How many states are in the US?', 50],
['What is 10 times 5?', 50]
];
var correctAnswers = 0;
var html = '';
var question;
var answer;
var response;
var correct = [];
var wrong = [];
function buildList(arr){
var listHTML = '<ol>';
for (var i=0; i<arr.length; i++){
listHTML += '<li>' + arr[i] + '</li>';
}
listHTML += '</ol>';
return listHTML;
}
for (var i=0; i<questions.length; i++){
question = questions[i][0];
answer = questions[i][1];
response = prompt(question);
response = parseInt(response);
if (response === answer){
correctAnswers += 1;
correct.push(question);
} else {
wrong.push(question);
}
}
html = 'You got ' + correctAnswers + ' question(s) right.'
html += '<h2>You got these questions correct:</h2>';
html += buildList(correct);
html += '<h2>You got these questions wrong:</h2>';
html += buildList(wrong);
print(html);
以上是关于javascript 询问并评分问题的主要内容,如果未能解决你的问题,请参考以下文章
基于规则评分的密码强度检测算法分析及实现(JavaScript)
Javascript 实现简单的星级评分功能
javascript 属性和基于事件的评分
javascript 更新环境评分
JavaScript 评分
如何知道特定用户是不是对 Android 应用进行了评分?