forked from ANKAN-MUKHOPADHYAY/JavaScript_QUIZ
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddQuestion.js
More file actions
Latest commit
48 lines (39 loc) · 1.3 KB
/
Copy pathaddQuestion.js
File metadata and controls
48 lines (39 loc) · 1.3 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
functionaddnewQuestion(){
varcategory=document.getElementById('category').value;
varfileName=getQuestionData(category);
console.log(fileName);
varoptions=newArray();
options.push(document.getElementById('opt1').value);
options.push(document.getElementById('opt2').value);
options.push(document.getElementById('opt3').value);
options.push(document.getElementById('opt4').value);
varquestionNew=newObject();
questionNew.question=document.getElementById('quest').value;
questionNew.choices=options;
questionNew.correct=document.getElementById('Correct').value;
console.log(questionNew);
vary=newXMLHttpRequest();
y.onreadystatechange=function(){
if(this.readyState==4){
vardata=JSON.parse(this.responseText);
//console.log(data.questions);
data.questions.push(questionNew);
console.log(JSON.stringify(data));
}
};
y.open('GET',fileName,true);
y.setRequestHeader("Content-Type","application/json");
y.send();
//console.log(currentData);
}
functiongetQuestionData(a){
if(a=="Bootstrap"){
return'data/bootstrapquestionset.json';
}elseif(a=="JavaScript"){
return'data/javascriptquestionset.json';
}elseif(a=="Ajax"){
return'data/ajaxquestionset.json';
}elseif(a=="HTML"){
return'data/htmlquestionset.json';
}
}