site-perso-poly/static/js/utils.js
Djalim Simaila 904d8daee6
All checks were successful
DEPLOY / deploy (push) Successful in 12s
feat: update navigation links and add new pages for improved user experience
- Change "Surprise :)" link to "Vibe check" across multiple HTML files for consistency and clarity.
- Add a new "about.html" page to provide information about the author.
- Introduce a new "quizz.html" page for user interaction and engagement.
- Create new project pages for "Lieutenant Champignon" and "Pong" to showcase additional projects.
- Remove outdated project pages and links to streamline the project section.
- Add new assets including images and PDFs to enhance content presentation.
- Update JavaScript functions for form validation and score calculation in the quizz page.
- Improve styling in CSS for better visual hierarchy and layout consistency.
2025-02-23 19:55:42 +01:00

79 lines
2.3 KiB
JavaScript

function hide(element) {
element.classList.add("hidden");
}
function unhide(element) {
element.classList.remove("hidden");
}
function toggle_all_header_links() {
const headerLinks = document.querySelector("header > .links");
const button_link = document.querySelector("header > button");
headerLinks.classList.toggle("display_links");
button_link.textContent = headerLinks.classList.contains("display_links")
? "▲"
: "▼";
}
function validate() {
let fname = document.getElementById("fname").value.trim();
let lname = document.getElementById("lname").value.trim();
let birth = document.getElementById("birth").value.trim();
let email = document.getElementById("email").value.trim();
let phone = document.getElementById("phone").value.trim();
let mcCreator = document.querySelector("input[name='mc_creator']:checked");
let worth = document.getElementById("worth").value.trim();
let emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
let phonePattern = /^\+?[0-9]{7,15}$/;
let birthPattern = /^(\d{4})-(\d{2})-(\d{2})$/; // Format YYYY-MM-DD
if (fname === "" || lname === "") {
alert("First name and last name are required.");
return;
}
if (!birthPattern.test(birth)) {
alert("Please enter a valid birthdate in YYYY-MM-DD format.");
return;
}
if (!emailPattern.test(email)) {
alert("Please enter a valid email address.");
return;
}
if (!phonePattern.test(phone)) {
alert("Please enter a valid phone number.");
return;
}
if (!mcCreator) {
alert("Please select the creator of Minecraft.");
return;
}
if (worth === "" || isNaN(worth) || worth < 0) {
alert("Please enter a valid worth in euros.");
return;
}
calculateScore();
}
function calculateScore() {
let score = 0;
let os = document.getElementById("os-select").value;
let mcCreator = document.querySelector(
"input[name='mc_creator']:checked",
).value;
let voca = document.getElementById("voca").value.trim().toLowerCase();
let worth = parseFloat(document.getElementById("worth").value);
let sns = document.getElementById("sns-select").value;
if (os === "linux") score += 1;
if (mcCreator === "miku") score += 1;
if (voca === "electric angel") score += 1;
if (worth > 5000000) score += 1;
if (sns === "Twitter") score += 1;
alert("Your score is: " + score + "/5");
}