diff --git a/app.js b/app.js
index eb6e8bc..d95f63c 100644
--- a/app.js
+++ b/app.js
@@ -335,6 +335,7 @@ function startGame() {
game.currentRound = 0;
game.correctCount = 0;
game.mistakes = [];
+ game.lastAnswer = null;
document.getElementById('score-correct').textContent = '0';
document.getElementById('score-total').textContent = '0';
@@ -352,7 +353,12 @@ function nextRound() {
game.currentRound++;
game.answered = false;
- game.correctAnswer = randInt(game.range.min, game.range.max);
+ let num;
+ do {
+ num = randInt(game.range.min, game.range.max);
+ } while (num === game.lastAnswer && game.range.min !== game.range.max);
+ game.correctAnswer = num;
+ game.lastAnswer = num;
document.getElementById('score-total').textContent = game.currentRound;
document.getElementById('score-correct').textContent = game.correctCount;
@@ -382,7 +388,8 @@ function renderChoices() {
choiceArea.classList.remove('hidden');
numpadArea.classList.add('hidden');
- const choices = generateChoices(game.correctAnswer, [game.range.min, game.range.max], 3);
+ const nonpos = ['roman', 'greek', 'slavonic', 'hebrew'];
+ const choices = generateChoices(game.correctAnswer, [game.range.min, game.range.max], 3, nonpos.includes(game.system));
choices.forEach((val, i) => {
const btn = document.getElementById('choice-' + i);
btn.textContent = val;
diff --git a/index.html b/index.html
index 7568952..91a1558 100644
--- a/index.html
+++ b/index.html
@@ -10,7 +10,7 @@
-
+
@@ -155,10 +155,10 @@
-
+
diff --git a/numerals.js b/numerals.js
index 5c57c25..d1b9c31 100644
--- a/numerals.js
+++ b/numerals.js
@@ -191,17 +191,19 @@ function toHebrew(num) {
return letters.slice(0, -1).join('') + HEB_GERSHAYIM + letters[letters.length - 1];
}
-export function generateChoices(correctAnswer, allRanges, count = 3) {
+export function generateChoices(correctAnswer, allRanges, count = 3, matchLastDigit = false) {
const choices = new Set([correctAnswer]);
const [min, max] = allRanges;
+ const useLastDigit = matchLastDigit && correctAnswer > 10;
let attempts = 0;
while (choices.size < count && attempts < 100) {
let wrong;
- const offset = Math.floor(Math.random() * 20) + 1;
- if (Math.random() < 0.5) {
- wrong = correctAnswer + offset;
+ if (useLastDigit) {
+ const offset = (Math.floor(Math.random() * 20) + 1) * 10;
+ wrong = Math.random() < 0.5 ? correctAnswer + offset : correctAnswer - offset;
} else {
- wrong = correctAnswer - offset;
+ const offset = Math.floor(Math.random() * 20) + 1;
+ wrong = Math.random() < 0.5 ? correctAnswer + offset : correctAnswer - offset;
}
if (wrong >= min && wrong <= max && wrong !== correctAnswer) {
choices.add(wrong);
@@ -209,7 +211,14 @@ export function generateChoices(correctAnswer, allRanges, count = 3) {
attempts++;
}
while (choices.size < count) {
- const r = min + Math.floor(Math.random() * (max - min + 1));
+ let r;
+ if (useLastDigit) {
+ do {
+ r = min + Math.floor(Math.random() * (max - min + 1));
+ } while (r % 10 !== correctAnswer % 10 && choices.size < count + 50);
+ } else {
+ r = min + Math.floor(Math.random() * (max - min + 1));
+ }
choices.add(r);
}
const arr = Array.from(choices);
diff --git a/sw.js b/sw.js
index 70ae136..2d0a4d5 100644
--- a/sw.js
+++ b/sw.js
@@ -1,4 +1,4 @@
-const CACHE_NAME = 'numnum-v37';
+const CACHE_NAME = 'numnum-v38';
const ASSETS = [
'/',
'/index.html',