-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (31 loc) · 1.18 KB
/
Copy pathscript.js
File metadata and controls
36 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
document.addEventListener('DOMContentLoaded', function() {
const keyboardLayout = [
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M']
];
const keyboardContainer = document.getElementById('keyboard');
const textInput = document.getElementById('textInput');
const textToType = document.getElementById('textToType').innerText;
let currentCharIndex = 0;
function createKeyboard() {
keyboardLayout.forEach(row => {
row.forEach(key => {
const keyButton = document.createElement('button');
keyButton.innerText = key;
keyButton.addEventListener('click', () => handleKeyPress(key));
keyboardContainer.appendChild(keyButton);
});
});
}
function handleKeyPress(key) {
if (key === textToType[currentCharIndex].toUpperCase()) {
currentCharIndex++;
textInput.value += key;
if (currentCharIndex === textToType.length) {
alert("You've typed the full text!");
}
}
}
createKeyboard();
});