This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
95 lines (81 loc) · 2.73 KB
/
index.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
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
var names = [
{
question: 'This is my first question',
answer: 'this is the answer for 1'
},
{
question: 'This is my second question',
answer: 'this is the answer for 2'
},
{
question: 'This is my third question',
answer: 'this is the answer for 3'
},
{
question: 'This is my fourth question',
answer: 'this is the answer for 4'
},
{
question: 'This is my fifth question',
answer: 'this is the answer for 5'
},
]
//console.log(names)
$('#loader').modal({
backdrop: 'static',
keyboard: false
})
$('#loader').modal('show');
window.onload = function(){
$('#loader').modal('hide');
}
names.forEach(function(value, index) {
var mainDiv = document.createElement('div')
mainDiv.className = 'd-flex justify-content-center align-items-center vh-100'
var mainCard = document.createElement('div')
mainCard.className = 'card'
var cardHeader = document.createElement('div')
cardHeader.className = 'card-header py-4 px-5'
var question = document.createElement('h2')
question.id = 'question_' + index
question.innerHTML = 'Question #' + (index + 1) + ': ' + value.question
var cardBody = document.createElement('div')
cardBody.className = 'card-body'
var answerForm = document.createElement('form')
answerForm.method = 'post'
answerForm.enctype = 'multipart/form-data'
answerForm.className = 'text-center'
var formGroup = document.createElement('div')
formGroup.className = 'form-group'
var formLabel = document.createElement('label')
formLabel.for = 'answer_' + index
formLabel.innerHTML = 'Answer'
var formInput = document.createElement('input')
formInput.type = 'text'
formInput.className = 'form-control'
formInput.id = 'answer_' + index
formInput.placeholder = 'Your Answer'
var submitBtn = document.createElement('button')
submitBtn.className = 'btn btn-primary'
submitBtn.id = 'submit_' + index
submitBtn.type = 'submit'
submitBtn.innerHTML = 'Submit'
submitBtn.onclick = function(e) {
e.preventDefault()
if (formInput.value === value.answer) {
window.alert('Answer is correct')
} else {
window.alert('Answer is wrong')
}
}
cardHeader.appendChild(question)
mainCard.appendChild(cardHeader)
mainDiv.appendChild(mainCard)
formGroup.appendChild(formLabel)
formGroup.appendChild(formInput)
answerForm.appendChild(formGroup)
answerForm.appendChild(submitBtn)
cardBody.appendChild(answerForm)
mainCard.appendChild(cardBody)
document.getElementById('allQuestions').appendChild(mainDiv)
})