corrections + update js formulaire
This commit is contained in:
+17
-4
@@ -3,10 +3,13 @@ const affichageGéo = document.getElementById("géolocalisation");
|
||||
const affichageConso = document.getElementById("consommation");
|
||||
const boutonPlus = document.getElementById("plus");
|
||||
const boutonMoins = document.getElementById("moins");
|
||||
const mot_vehicules = document.getElementById("mot_vehic");
|
||||
const PRIX_GPS = 30;
|
||||
const PRIX_CONSOMMATION = 15;
|
||||
const zoneMsg = document.getElementById("msg");
|
||||
const txt_restant = document.getElementById("txt_restant");
|
||||
const MAX = 500;
|
||||
let nbVehicules = 1;
|
||||
let totalargent = 0;
|
||||
function mettreAJourGPS() {
|
||||
affichageNb.textContent = nbVehicules;
|
||||
affichageGéo.textContent = nbVehicules * PRIX_GPS;
|
||||
@@ -16,19 +19,29 @@ function mettreAJourCONSO() {
|
||||
affichageConso.textContent = nbVehicules * PRIX_CONSOMMATION;
|
||||
}
|
||||
function mettreAJourTOTAL() {
|
||||
affichageNb.textContent = totalargent;
|
||||
affichageGéo.textContent = totalargent + PRIX_GPS + PRIX_CONSOMMATION;
|
||||
affichageNb.textContent = nbVehicules;
|
||||
affichageGéo.textContent = nbVehicules * PRIX_GPS;
|
||||
affichageConso.textContent = nbVehicules * PRIX_CONSOMMATION;
|
||||
}
|
||||
boutonPlus.addEventListener("click", function () {
|
||||
nbVehicules = nbVehicules + 1;
|
||||
(mettreAJourGPS(), mettreAJourCONSO());
|
||||
if (nbVehicules > 99) {
|
||||
nbVehicules = nbVehicules - 1;
|
||||
}
|
||||
if (nbVehicules === 1) mot_vehicules.textContent = "véhicule";
|
||||
else mot_vehicules.textContent = "véhicules";
|
||||
(mettreAJourGPS(), mettreAJourCONSO());
|
||||
});
|
||||
boutonMoins.addEventListener("click", function () {
|
||||
if (nbVehicules > 1) {
|
||||
nbVehicules = nbVehicules - 1;
|
||||
}
|
||||
if (nbVehicules === 1) mot_vehicules.textContent = "véhicule";
|
||||
else mot_vehicules.textContent = "véhicules";
|
||||
(mettreAJourGPS(), mettreAJourCONSO());
|
||||
});
|
||||
zoneMsg.addEventListener("input", function () {
|
||||
const reste = MAX - zoneMsg.value.length;
|
||||
txt_restant.textContent = reste;
|
||||
txt_restant.style.color = reste < 50 ? "red" : "black";
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user