Skip to content

Commit 12ad01e

Browse files
authored
Add files via upload
1 parent 9a12d6e commit 12ad01e

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

test.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,19 @@ <h2>查碼練習</h2>
10401040
const textToCompare = textOutput.value;
10411041
encodingResults.innerHTML = '';
10421042

1043-
const characters = textToSearch.split('').slice(0, 10);
1043+
// 計算連續正確字元的數量
1044+
let correctCharsCount = 0;
1045+
for (let i = 0; i < textToCompare.length && i < textToSearch.length; i++) {
1046+
if (textToCompare[i] === textToSearch[i]) {
1047+
correctCharsCount++;
1048+
} else {
1049+
break;
1050+
}
1051+
}
1052+
1053+
// 根據正確字數計算查碼區塊的起始索引
1054+
const lookupStartIndex = Math.floor(correctCharsCount / 10) * 10;
1055+
const characters = textToSearch.split('').slice(lookupStartIndex, lookupStartIndex + 10);
10441056

10451057
// 固定顯示10個欄位
10461058
for (let i = 0; i < 10; i++) {
@@ -1054,9 +1066,10 @@ <h2>查碼練習</h2>
10541066
if (i < characters.length) {
10551067
const char = characters[i];
10561068
charLabel.textContent = char;
1057-
1058-
if (i < textToCompare.length) {
1059-
if (char === textToCompare[i]) {
1069+
const globalIndex = lookupStartIndex + i;
1070+
1071+
if (globalIndex < textToCompare.length) {
1072+
if (char === textToCompare[globalIndex]) {
10601073
charLabel.classList.add('correct-char');
10611074
} else {
10621075
charLabel.classList.add('incorrect-char');

0 commit comments

Comments
 (0)