-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddquestions.js
25 lines (24 loc) · 925 Bytes
/
addquestions.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
var questionForm = document.getElementById("add-question") || {};
questionForm.onsubmit = processForm;
function processForm(){
var newQuestion = {
question: questionForm.question.value,
choiceA: questionForm.choiceA.value,
choiceB: questionForm.choiceB.value,
choiceC: questionForm.choiceC.value,
choiceD: questionForm.choiceD.value,
correct: questionForm.correct.value
};
// if local storage contains questions, pull and update stored data. Store new object otherwise
if(localStorage.getItem("questions")){
var questions = JSON.parse(localStorage.getItem("questions"));
questions.push(newQuestion);
localStorage.setItem("questions", JSON.stringify(questions));
}
else{
var questions = [newQuestion];
localStorage.setItem("questions", JSON.stringify(questions));
}
questionForm.reset();
return false;
}