-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
133 lines (104 loc) · 3.76 KB
/
main.js
File metadata and controls
133 lines (104 loc) · 3.76 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const questions = [
{
question: 'How can you add a comment in a JavaScript?',
answer: '//This is a comment'
},
{
question: 'How to insert a comment that has more than one line?',
answer: '/*This comment has more than one line*/'
},
{
question: 'How do you round the number 7.25, to the nearest integer?',
answer: 'Math.round(7.25)'
},
{
question: 'JavaScript is the same as Java?',
answer: 'False'
},
{
question: 'Which event occurs when the user clicks on an HTML element? ',
answer: 'onclick'
}, {
question: 'Which operator is used to assign a value to a variable?',
answer: '='
}, {
question: 'Is JavaScript case-sensitive?',
answer: 'Yes'
}, {
question: 'Inside which HTML element do we put the JavaScript?',
answer: '</script>'
}, {
question: 'What is a boolean?',
answer: 'true or false'
},
]
var randomQuestion = questions[Math.floor((Math.random()*questions.length-1)+1)];
let showQuestion = randomQuestion.question
let showAnswer = randomQuestion.answer
let label = document.createElement("label");
label.setAttribute("id", "someid")
label.innerHTML = showQuestion;
let parent = document.getElementsByClassName("flashcard")[0];
parent.appendChild(label);
function pressAnswer(){
document.getElementById("someid").innerText = showAnswer
}
function submitFlashcard(){
let inputQuestionField = document.getElementById("inputQuestion")
let question = inputQuestionField.value
let inputAnswerField = document.getElementById("inputAnswer")
let answer = inputAnswerField.value
questions.push({question, answer})
callList();
updateCounters();
inputQuestionField.value = null;
inputAnswerField.value = null;
}
function callList() {
let parentListQuestions = document.getElementById("listQuestions")
parentListQuestions.innerHTML = ""
for (var i = 0; i <= (questions.length- 1); i++){
let listQuestions = document.createElement("div");
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.setAttribute("onchange", "toggleDone.bind(this)()")
checkbox.checked = false;
listQuestions.appendChild(checkbox)
listQuestions.setAttribute("class", "listItem")
listQuestions.innerHTML += questions[i].question
parentListQuestions.appendChild(listQuestions);
}
}
callList();
function toggleDone() {
var checkbox = this;
// check the checked status of the checkbox
if (checkbox.checked) {
// the "completed" class is set on the parent element, the <li>
checkbox.parentElement.className = "toDelete";
} else {
checkbox.parentElement.className = "listItem";
}
}
function cleanUpFlashcards() {
//var list = document.getElementById("todolist");
var itemsToDelete = document.getElementsByClassName("toDelete");
// Reverse loop through the done todo items so we can remove them without changing the index of the remaining items when we remove them
for (var i = itemsToDelete.length; i > 0; i--) {
listQuestions.removeChild(itemsToDelete[i-1]);
}
updateCounters();
}
function updateCounters(){
var totalCount = document.getElementById('total-count');
var totalQuestions = document.getElementsByClassName("listItem").length;
totalCount.innerHTML = totalQuestions;
}
updateCounters();
function nextQuestion(){
var otherQuestion = questions[Math.floor((Math.random()*questions.length-1)+1)];
//var newFlashcard = document.getElementById('flashcard');
showQuestion = otherQuestion.question
showAnswer = otherQuestion.answer
label.innerHTML = showQuestion;
}