diff --git a/assets/js/main.js b/assets/js/main.js index 8dc2f4c..efadd89 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -308,6 +308,11 @@ if (localStorage.getItem("theme") == "light") { toggleDarkMode(); } + + // Set age correctly (cuz sbatti farlo ogni + // anno, toi meme tu sais) + let age_span = document.querySelector("#age"); + age_span.textContent = calculateAge("1999-10-15"); })(); function toggleDarkMode() { @@ -321,3 +326,17 @@ function toggleDarkMode() { document.documentElement.style.setProperty("color-scheme", theme); localStorage.setItem("theme", theme); } + +function calculateAge(birthDate) { + const today = new Date(); + const birth = new Date(birthDate); + let age = today.getFullYear() - birth.getFullYear(); + const monthDifference = today.getMonth() - birth.getMonth(); + + // Check if the birthday has not occurred yet this year + if (monthDifference < 0 || (monthDifference === 0 && today.getDate() < birth.getDate())) { + age--; + } + + return age; +} diff --git a/index.html b/index.html index b4ef9f9..0b7187a 100644 --- a/index.html +++ b/index.html @@ -115,7 +115,7 @@