Skip to content

Commit 546e89b

Browse files
committed
Added Alphabet and Vowel game extension
1 parent b42b64e commit 546e89b

4 files changed

Lines changed: 154 additions & 0 deletions

File tree

Alphabet and Vowel Game/app.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
2+
const vowels = 'AEIOU';
3+
let score = 0;
4+
let target = 'vowel';
5+
6+
document.addEventListener('DOMContentLoaded', () => {
7+
const alphabetGrid = document.getElementById('alphabetGrid');
8+
const feedback = document.getElementById('feedback');
9+
const instruction = document.getElementById('instruction');
10+
const resetButton = document.getElementById('resetButton');
11+
12+
const shuffleArray = array => array.sort(() => Math.random() - 0.5);
13+
14+
const generateButtons = () => {
15+
shuffleArray(alphabet).forEach(letter => {
16+
const button = document.createElement('button');
17+
button.textContent = letter;
18+
button.addEventListener('click', () => checkLetter(letter, button));
19+
alphabetGrid.appendChild(button);
20+
});
21+
};
22+
23+
const checkLetter = (letter, button) => {
24+
if ((target === 'vowel' && vowels.includes(letter)) ||
25+
(target === 'consonant' && !vowels.includes(letter))) {
26+
button.classList.add('correct');
27+
score++;
28+
feedback.textContent = 'Correct!';
29+
} else {
30+
button.classList.add('wrong');
31+
feedback.textContent = 'Try again!';
32+
}
33+
34+
button.disabled = true;
35+
36+
if (score === 5) {
37+
target = 'consonant';
38+
instruction.textContent = 'Now click on all the consonants!';
39+
score = 0;
40+
feedback.textContent = '';
41+
}
42+
};
43+
44+
const resetGame = () => {
45+
alphabetGrid.innerHTML = '';
46+
feedback.textContent = '';
47+
instruction.textContent = 'Click on all the vowels!';
48+
score = 0;
49+
target = 'vowel';
50+
generateButtons();
51+
};
52+
53+
resetButton.addEventListener('click', resetGame);
54+
55+
generateButtons();
56+
});

Alphabet and Vowel Game/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Alphabet and Vowel Game</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Alphabet and Vowel Game</h1>
12+
<p id="instruction">Click on all the vowels!</p>
13+
<div class="alphabet-grid" id="alphabetGrid"></div>
14+
<p id="feedback"></p>
15+
<button id="resetButton">Reset Game</button>
16+
</div>
17+
<script src="app.js"></script>
18+
</body>
19+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "Alphabet and Vowel ",
4+
"version": "1.0",
5+
"description": "An Alphabet and Vowel game a Chrome extension.",
6+
"action": {
7+
"default_popup": "index.html"
8+
},
9+
"permissions":[]
10+
}

Alphabet and Vowel Game/style.css

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
body {
2+
font-family: 'Arial', sans-serif;
3+
display: flex;
4+
justify-content: center;
5+
align-items: center;
6+
height: 100vh;
7+
margin: 0;
8+
background-color: #16d1e2;
9+
}
10+
11+
.container {
12+
text-align: center;
13+
background: #fff;
14+
padding: 20px;
15+
border-radius: 10px;
16+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
17+
}
18+
19+
h1 {
20+
color: #333;
21+
}
22+
23+
.alphabet-grid {
24+
display: grid;
25+
grid-template-columns: repeat(6, 50px);
26+
gap: 10px;
27+
justify-content: center;
28+
margin: 20px 0;
29+
}
30+
31+
.alphabet-grid button {
32+
background-color: #008cba;
33+
color: white;
34+
border: none;
35+
border-radius: 5px;
36+
width: 50px;
37+
height: 50px;
38+
font-size: 18px;
39+
cursor: pointer;
40+
transition: background-color 0.3s;
41+
}
42+
43+
.alphabet-grid button.correct {
44+
background-color: #4caf50;
45+
}
46+
47+
.alphabet-grid button.wrong {
48+
background-color: #f44336;
49+
}
50+
51+
#feedback {
52+
margin-top: 20px;
53+
font-size: 20px;
54+
}
55+
56+
#resetButton {
57+
background-color: #ff9800;
58+
color: white;
59+
border: none;
60+
border-radius: 5px;
61+
padding: 10px 20px;
62+
font-size: 18px;
63+
cursor: pointer;
64+
transition: background-color 0.3s;
65+
}
66+
67+
#resetButton:hover {
68+
background-color: #e68900;
69+
}

0 commit comments

Comments
 (0)