-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathLanguage Learning Flashcards
More file actions
39 lines (39 loc) · 1.38 KB
/
Language Learning Flashcards
File metadata and controls
39 lines (39 loc) · 1.38 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
<!-- Objective: Develop a language learning flashcard tool. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Language Learning Flashcards</title>
</head>
<body>
<h2>Add New Flashcard</h2>
<form id="flashcardForm">
<input type="text" id="word" placeholder="Word in Target Language" required>
<input type="text" id="translation" placeholder="Translation or Definition" required>
<button type="submit">Add Flashcard</button>
</form>
<div id="flashcardsContainer"></div>
<script>
let flashcards = JSON.parse(localStorage.getItem('flashcards')) || [];
document.getElementById('flashcardForm').addEventListener('submit', function(e) {
e.preventDefault();
const word = document.getElementById('word').value.trim();
const translation = document.getElementById('translation').value.trim();
flashcards.push({ word, translation });
localStorage.setItem('flashcards', JSON.stringify(flashcards));
displayFlashcards();
this.reset();
});
function displayFlashcards() {
const container = document.getElementById('flashcardsContainer');
container.innerHTML = ''; // Clear existing flashcards
flashcards.forEach(flashcard => {
const flashcardDiv = document.createElement('div');
flashcardDiv.innerHTML = `<div>Word: ${flashcard.word}</div><div>Translation: ${flashcard.translation}</div>`;
container.appendChild(flashcardDiv);
});
}
displayFlashcards();
</script>
</body>
</html>