-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsightwords.html
More file actions
67 lines (60 loc) · 1.6 KB
/
sightwords.html
File metadata and controls
67 lines (60 loc) · 1.6 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sight Words Board Game</title>
<link rel="stylesheet" href="styles.css">
<style>
#board {
display: grid;
grid-template-columns: repeat(4, 100px);
grid-template-rows: repeat(4, 100px);
}
.tile {
border: 1px solid black;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Sight Words Board Game</h1>
<div id="board"></div>
<div id="message"></div>
<script>
// Array of sight words
const sightWords = [
"and", "the", "is", "in", "it",
"to", "you", "can", "we", "my"
];
// Shuffle function to randomize array
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
// Generate random word from sightWords
shuffle(sightWords);
const targetWord = sightWords[0];
// Display board with sight words
const board = document.getElementById('board');
sightWords.forEach(word => {
const tile = document.createElement('div');
tile.classList.add('tile');
tile.textContent = word;
tile.addEventListener('click', () => {
if (word === targetWord) {
document.getElementById('message').textContent = 'Congratulations! You found the word.';
} else {
document.getElementById('message').textContent = 'Try again!';
}
});
board.appendChild(tile);
});
</script>
</body>
</html>