-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (48 loc) · 1.91 KB
/
script.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var contentArray = localStorage.getItem('items') ? JSON.parse(localStorage.getItem('items')) : [];
document.getElementById("save_card").addEventListener("click", () => {
addFlashcard();
});
document.getElementById("delete_cards").addEventListener("click", () => {
localStorage.clear();
flashcards.innerHTML = '';
contentArray = [];
});
document.getElementById("show_card_box").addEventListener("click", () => {
document.getElementById("create_card").style.display = "block";
});
document.getElementById("close_card_box").addEventListener("click", () => {
document.getElementById("create_card").style.display = "none";
});
flashcardMaker = (text) => {
const flashcard = document.createElement("div");
const question = document.createElement('h2');
const answer = document.createElement('h2');
flashcard.className = 'flashcard';
question.setAttribute("style", "border-top:1px solid red; padding: 15px; margin-top:30px");
question.textContent = text.my_question;
answer.setAttribute("style", "text-align:center; display:none; color:red");
answer.textContent = text.my_answer;
flashcard.appendChild(question);
flashcard.appendChild(answer);
flashcard.addEventListener("click", () => {
if(answer.style.display == "none")
answer.style.display = "block";
else
answer.style.display = "none";
})
document.querySelector("#flashcards").appendChild(flashcard);
}
contentArray.forEach(flashcardMaker);
addFlashcard = () => {
const question = document.querySelector("#question");
const answer = document.querySelector("#answer");
let flashcard_info = {
'my_question' : question.value,
'my_answer' : answer.value
}
contentArray.push(flashcard_info);
localStorage.setItem('items', JSON.stringify(contentArray));
flashcardMaker(contentArray[contentArray.length - 1]);
question.value = "";
answer.value = "";
}