📅  最后修改于: 2023-12-03 15:07:31.631000             🧑  作者: Mango
这是一个用于测试命名线段,光线和线的在线测验程序。该程序将测试您对几何学中命名线段,光线和线的理解程度。
该程序使用JavaScript语言实现。以下是该程序的核心代码:
const questions = [
{type: 'segment', name: 'AB', options: ['AC', 'AD', 'AB']},
{type: 'ray', name: 'CD', options: ['CE', 'CD', 'CF']},
{type: 'line', name: 'EF', options: ['GH', 'EF', 'IJ']},
// ...更多的题目
];
let score = 0;
let currentQuestion = 0;
function displayQuestion() {
const question = questions[currentQuestion];
let questionHtml = `What type of segment is ${question.name}?<br><br>`;
for (let i = 0; i < question.options.length; i++) {
questionHtml += `${i + 1}. ${question.options[i]}<br>`;
}
questionHtml += `<br><button onClick="checkAnswer()">Submit Answer</button>`;
document.getElementById('question').innerHTML = questionHtml;
}
function checkAnswer() {
const question = questions[currentQuestion];
const selectedOption = document.querySelector('input[name="option"]:checked').value;
const answerIndex = question.options.indexOf(question.name);
const selectedOptionIndex = question.options.indexOf(selectedOption);
if (selectedOptionIndex === answerIndex) {
score++;
alert('Correct!');
} else {
alert(`Sorry, the correct answer is ${question.name}`);
}
currentQuestion++;
if (currentQuestion < questions.length) {
displayQuestion();
} else {
alert(`Quiz complete! Your score is ${score} out of ${questions.length}`);
}
}
displayQuestion();
在您的网页中添加以下代码片段即可使用:
<div id="question"></div>
<script src="quiz.js"></script>
通过以上代码,我们可以看出该程序使用JavaScript语言实现,可以测试您对几何学中命名线段,光线和线的理解程度,在测验结束后给出您最终得分。您只需添加以上代码片段并引入quiz.js文件,即可将该程序应用于您的网页中。