Created
July 27, 2025 17:51
-
-
Save NaiveInvestigator/f453a5d5850365b813b10ba2ffdf1b77 to your computer and use it in GitHub Desktop.
For CSE389 midterms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <title> | |
| wanna become a millionaire? | |
| </title> | |
| </head> | |
| <body> | |
| <table> | |
| <tr><td id='question'></td> <tr> | |
| <tr><td> <input type='checkbox' value = '' id = 'q0' name='quiz'></td> <tr> | |
| <tr><td> <input type='checkbox' value = '' id = 'q1' name='quiz'></td> <tr> | |
| <tr><td> <input type='checkbox' value = '' id = 'q2' name='quiz'></td> <tr> | |
| <tr><td> <input type='checkbox' value = '' id = 'q3' name='quiz'></td> <tr> | |
| <table> | |
| <button id='button' onclick= 'Submit()'>Answer</button> | |
| <script> | |
| quiz = [ | |
| { | |
| id: 1 , | |
| question: 'What is my first name?', | |
| options: ['Akid', 'Anis', 'Shalob', 'Skida'], | |
| correct_ans: 0, | |
| }, | |
| { | |
| id: 2, | |
| question: 'What is my last name?', | |
| options: ['Akid', 'Anis', 'Shalob', 'Skida'], | |
| correct_ans: 2, | |
| }, | |
| ]; | |
| index = 0; | |
| points = 0; | |
| function updateQuestion() { | |
| if (index >= quiz.length) { | |
| console.log("FInished Quiz"); | |
| return; | |
| } | |
| question = quiz[index]; | |
| questionDOM = document.getElementById('question'); | |
| questionDOM.textContent = question['question']; | |
| q1DOM = document.getElementById('q0'); | |
| q1DOM.value = question['options'][0]; | |
| q1DOM.after(question["options"][0]); | |
| q2DOM = document.getElementById('q1'); | |
| q2DOM.value = question['options'][1]; | |
| q2DOM.after(question["options"][1]); | |
| q3DOM = document.getElementById('q2'); | |
| q3DOM.value = question['options'][2]; | |
| q3DOM.after(question["options"][2]); | |
| q4DOM = document.getElementById('q3'); | |
| q4DOM.value = question['options'][3]; | |
| q4DOM.after(question["options"][3]); | |
| } | |
| function Submit() { | |
| console.log(`${index}`); | |
| if (index > quiz.length) { | |
| console.log("FInished Quiz"); | |
| return; | |
| } | |
| for (i = 0; i < 4; i++) | |
| { | |
| qDOM = document.getElementById(`q${i}`) | |
| if (qDOM.checked && quiz[index]['correct_ans'] == i) | |
| { | |
| points = points + 5; | |
| } | |
| } | |
| index = index + 1; | |
| console.log(`Points: ${points}`); | |
| updateQuestion(); | |
| } | |
| updateQuestion(); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment