Skip to content

Commit

Permalink
Add confirm.
Browse files Browse the repository at this point in the history
  • Loading branch information
wegret committed Jun 5, 2024
1 parent 5438fb6 commit a11af0a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<body>
<div id="content">
<h1>Reciter!</h1>
<div id="total_count_number"></div>
<div id="overall-stats"></div>

<div id="progress-container">
Expand All @@ -103,6 +104,8 @@ <h1>Reciter!</h1>
</div>

<script>
let total_count = 0;

let questions = []; // 题库
let prev_question = null; // 上次题目
let current_question = null; // 当前题目
Expand Down Expand Up @@ -172,6 +175,8 @@ <h1>Reciter!</h1>
if (storedWrongQuestions)
question_wrong = JSON.parse(storedWrongQuestions);

total_count = parseInt(localStorage.getItem('total_exercise_count'));

question_next();
displayOverallStats();
}
Expand Down Expand Up @@ -293,6 +298,8 @@ <h1>Reciter!</h1>

/* 计算并显示总体正确率 */
function displayOverallStats() {
document.getElementById('total_count_number').innerHTML = `<p>练习次数:${total_count ? total_count : 0}`;

let stats = localStorage.getItem('quiz_stats');
if (!stats) {
stats = {};
Expand Down Expand Up @@ -320,6 +327,11 @@ <h1>Reciter!</h1>

/* 更新统计信息 */
function history_update(questionId, isCorrect) {
if (total_count)
total_count = total_count + 1;
else
total_count = 1;

let stats = localStorage.getItem('quiz_stats');
if (!stats) {
stats = {};
Expand All @@ -342,16 +354,17 @@ <h1>Reciter!</h1>
}
else {
// 添加做错的题目
if (!question_wrong.some(question => question.id === questionId)) {
const wrongQuestion = questions.find(question => question.id === questionId);
if (wrongQuestion) {
question_wrong.push(wrongQuestion);
}
// if (!question_wrong.some(question => question.id === questionId)) { // 允许多次添加
const wrongQuestion = questions.find(question => question.id === questionId);
if (wrongQuestion) {
question_wrong.push(wrongQuestion);
}
// }
}

localStorage.setItem('quiz_stats', JSON.stringify(stats));
localStorage.setItem('question_wrong', JSON.stringify(question_wrong));
localStorage.setItem('total_exercise_count', total_count.toString());

displayOverallStats();
}
Expand Down

0 comments on commit a11af0a

Please sign in to comment.