-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (37 loc) · 1.18 KB
/
script.js
File metadata and controls
41 lines (37 loc) · 1.18 KB
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
// script.js — login + menu handler
// Antwaun
document.addEventListener("DOMContentLoaded", () => {
// LOGIN PAGE
const loginForm = document.getElementById("login-form");
if (loginForm) {
loginForm.addEventListener("submit", (e) => {
e.preventDefault();
const username = document.getElementById("username").value.trim();
if (!username) {
alert("Please enter your name to continue.");
return;
}
sessionStorage.setItem("mm_user", username);
window.location.href = "menu.html";
});
}
// MENU PAGE
const options = document.querySelectorAll(".option");
if (options.length > 0) {
options.forEach(option => {
option.addEventListener("click", () => {
const level = option.dataset.level || option.textContent.trim();
window.location.href = `quiz.html?level=${encodeURIComponent(level)}`;
});
});
// keyboard shortcut: 1-4 to choose
document.addEventListener("keydown", (e) => {
const map = { "1": 0, "2": 1, "3": 2, "4": 3 };
if (map[e.key] !== undefined) {
const idx = map[e.key];
const opt = options[idx];
if (opt) opt.click();
}
});
}
});