In: Computer Science
Here is an array of multiple choice questions.
var questions = [
{Q: "What's 2 + 2?",
A: "4",
B: "5',
C: "6",
ANS: "A" },
{Q: "What is 2 + 3?",
A: "5",
B: "6",
C: "8",
ANS: "A" },
];
In a separate JavaScript file, define a class of object called Question. The constructor takes an object literal that describes one question, and an integer representing the question number. It constructs the question in a paragraph, the answers in radio buttons with their corresponding labels, and makes a Grade button using .append(). The Question object also contains an addToDOM method, which appends the question to a given DOM element (the addToDOM method adds structure to the document at a given destination, and the destination is given by an argument to the addToDOM method). Please use JQuery.
class Question {
constructor(q, qNum) {
this.qNum = qNum;
this.question = q['Q'];
this.optionA = q['A'];
this.optionB = q['B'];
this.optionC = q['C'];
this.optionD = q['D'];
this.answer = q['ANS'];
}
addToDOM (elem) {
s = '
' + this.qNum + ". " + this.question + "
";