-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
59 lines (48 loc) · 2.1 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Multiple Choice Question Example</title>
</head>
<body>
<h1><a href="https://github.com/hrsummers/california-community-property-MC">Home</a> <a href="https://github.com/hrsummers/california-community-property-MC/blob/312428343a40820f545780731ec3fdf4695f4caa/Web%20Pages/Contact%20Us">Contact Us</a><h1>
<h1>Multiple Choice Question 1</h1>
<p>What is the capital of France?</p>
<form>
<input type="radio" id="answer1" name="answer" value="1"><label for="answer1">A. London</label><br>
<input type="radio" id="answer2" name="answer" value="2"><label for="answer2">B. Berlin</label><br>
<input type="radio" id="answer3" name="answer" value="3"><label for="answer3">C. Paris</label><br>
<input type="radio" id="answer4" name="answer" value="4"><label for="answer4">D. Rome</label><br>
<input type="submit" value="Submit">
</form>
<p id="result">
<!-- The correct answer will be displayed here after the user submits their answer -->
</p>
<script>
// Get a reference to the form and result elements
var form = document.querySelector('form');
var result = document.querySelector('#result');
// Add an event listener for when the form is submitted
form.addEventListener('submit', function(event) {
// Prevent the form from being submitted
event.preventDefault();
// Get the selected answer
var selected = document.querySelector('input[name="answer"]:checked');
// Check if an answer was selected
if (selected) {
// Get the value of the selected answer
var answer = selected.value;
// Check if the selected answer is correct
if (answer == 3) {
// If the selected answer is correct, show the result and set the text to "Correct"
result.style.display = 'block';
result.textContent = 'Correct';
} else {
// If the selected answer is incorrect, show the result and set the text to "Incorrect"
result.style.display = 'block';
result.textContent = 'Incorrect';
}
}
});
</script>
</body>
</html>