startit/MVC/MVC_quizz.html

42 lines
983 B
HTML
Raw Normal View History

2024-08-27 13:11:59 +02:00
<!DOCTYPE html>
<html lang="en">
2024-08-27 13:16:43 +02:00
2024-08-27 13:11:59 +02:00
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Model View Controller</title>
<style>
2024-08-27 13:16:43 +02:00
2024-08-27 13:11:59 +02:00
</style>
</head>
2024-08-27 13:16:43 +02:00
2024-08-27 13:11:59 +02:00
<body>
<div id="app"></div>
<script>
// Model
let questionIndex = 0;
let points = 0;
// view
updateView();
2024-08-27 13:16:43 +02:00
function updateView() {
2024-08-27 13:11:59 +02:00
let question;
if (questionIndex == 0) question = "Hva er 2 + 2 ?"
2024-08-27 13:16:43 +02:00
else if (questionIndex == 1) question = "Hva er hovedstaden i Sverige ?"
2024-08-27 13:11:59 +02:00
document.getElementById('app').innerHTML = /*HTML*/ `
2024-08-27 13:16:43 +02:00
<h1>${question}</h1>
2024-08-27 13:11:59 +02:00
Poeng: ${points}<br>
<input type="text">
2024-08-27 13:16:43 +02:00
<button onclick="next()">Next</button>
2024-08-27 13:11:59 +02:00
`;
};
2024-08-27 13:16:43 +02:00
// controller
function next() {
questionIndex++;
updateView();
}
2024-08-27 13:11:59 +02:00
</script>
</body>
2024-08-27 13:16:43 +02:00
2024-08-27 13:11:59 +02:00
</html>