-
Notifications
You must be signed in to change notification settings - Fork 0
/
flashcards.js
40 lines (28 loc) · 1.4 KB
/
flashcards.js
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
let flashcardsSection = document.querySelector(`.flashcardsSection`);
let questionsFromDatabase = localStorage.getItem(`questions`) ? JSON.parse(localStorage.getItem(`questions`)) : [];
if (questionsFromDatabase.length > 0 && flashcardsSection) {
console.log(`Questions From Database`, questionsFromDatabase);
questionsFromDatabase.forEach((ques, quesIndex) => {
let flashcardElement = document.createElement(`div`);
flashcardElement.className = `flashcard`;
let flashcardFront = document.createElement(`div`);
let flashcardBack = document.createElement(`div`);
flashcardFront.className = `front cardFace`;
flashcardBack.className = `back cardFace`;
let flaschcardFrontQuestion = document.createElement(`div`);
let flaschcardFrontChoices = document.createElement(`div`);
flaschcardFrontQuestion.className = `fcQuestion`;
flaschcardFrontChoices.className = `fcChoices`;
flaschcardFrontQuestion.innerHTML = ques.question;
flaschcardFrontChoices.innerHTML = ques.choices.join(`<br><br>`);
flashcardBack.innerHTML = ques.answer;
flashcardFront.append(flaschcardFrontQuestion);
flashcardFront.append(flaschcardFrontChoices);
flashcardElement.append(flashcardFront);
flashcardElement.append(flashcardBack);
flashcardElement.onclick = () => {
flashcardElement.classList.toggle(`flipped`);
}
flashcardsSection.append(flashcardElement);
})
}