Skip to content

Commit

Permalink
fix (validAge) : >13 (OpenClassrooms-Student-Center#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
codexarama committed Feb 24, 2021
1 parent 7924643 commit 972ddfe
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion starterOnly/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,52 @@ const validEmail = function (inputEmail) {
// VALIDATION DU CHAMP "Birthdate"
// format jj/mm/aaaa
// le joueur doit avoir plus de 13 ans
// ___________________________________

// calcul de l'âge du joueur
form.birthdate.addEventListener('blur', function () {
userAge(this);
});

let userAge = function () {

// récupération de la valeur du champ "date"
let userDateInput = form.birthdate.value;
//let userDateInput = document.getElementById("birthdate").value;
console.log(userDateInput);

// conversion de la valeur du champ "date" en objet
let userBirthdate = new Date(userDateInput);
console.log("userBirthdate"+ birthdate);

// différence entre la date de naissance et la date du jour
let difference = Date.now() - userBirthdate.getTime();

// calcul de l'âge
let age = new Date(difference);
let calculateAge = Math.abs(age.getUTCFullYear() - 1970);
console.log(calculateAge);
return calculateAge;
}

// Vérification âge > 13 ans
form.birthdate.addEventListener('change', function () {
validAge(this);
});

function validAge () {
if (userAge()>=13) {
errorBirthdate.innerHTML = '';
return true
} else {
errorBirthdate.innerHTML = 'Vous devez avoir plus de 13 ans pour participer';
return false
}
}

form.birthdate.addEventListener('focus', function () {
userAge(this);
validAge(this);
});

// VALIDATION DU CHAMP "Quantity"
// nombre de participations comprimse entre 0 et 99
Expand Down

0 comments on commit 972ddfe

Please sign in to comment.