Files
webtech/ora7/roxfort.js

26 lines
834 B
JavaScript
Raw Permalink Normal View History

2025-11-14 17:30:19 +01:00
function calculateYearsSince(dateString) {
const date = new Date(dateString);
const diff = Date.now() - date.getTime();
return new Date(diff).getUTCFullYear() - 1970;
}
console.log(calculate2("2001-09-01"));
const form = document.getElementById('hogwarts-form');
form.dateofbirth.addEventListener("input", function(event){
console.log(form.dateofbirth.value);
const age = calculateYearsSince(form.dateofbirth.value);
console.log(age);
if(age >= 11){
form.dateofbirth.setCustomValidity('');
}else{
form.dateofbirth.setCustomValidity('young');
}
})
form.house.addEventListener('change', function (event){
const houseColor = form.house.options[form.house.selectedIndex].dataset.colorPrimary;
console.log(houseColor);
document.body.style.backgroundColor = houseColor;
})