https://docs.google.com/spreadsheets/d/1krd-tvfspL5HwDCFasPdKcGm6aZSCYZcr5PtplXkipY/edit?usp=sharing
l'opérateur &&
const myForEach = (tab, callback) => {
for (let i = 0; i < tab.length; i++) {
callback(tab[i], i, tab);
}
};
const notes = [12, 7, 17, 5, 19];
// 👉 Si la note < 6 on met Ajourné
myForEach(notes, (n, i, t) => n < 7 && (t[i] = "AJ"));
📦Cas des objets
Le DOM
Calculer la moyenne d'un groupe avec des étudiants absents
📒 Selecteur = p
const students = document.querySelectorAll("p");
let sum = 0;
let count = 0;
for (const student of students) {
const mark = Number(student.dataset.mark);
if (!isNaN(mark)) {
sum += mark;
count++;
}
}
const average = count
? (sum / count).toFixed(2)
: "Aucune note";
const students = document.querySelectorAll("p");
let sum = 0;
let count = 0;
for (const student of students) {
const mark = Number(student.dataset.mark);
if (!isNaN(mark)) {
sum += mark;
count++;
}
}
const average = count
? (sum / count).toFixed(2)
: "Aucune note";
Choix d'un selecteur !
// utilisez le bon selecteur
const elements = document.querySelectorAll("[data-mark]");
let sum = 0;
for (const el of elements) {
sum += Number(el.dataset.mark);
}
const average = sum / elements.length;
;
See the Pen UsetherightSelector by dupont (@dupontcodepen) on CodePen.
En action : github
// 🥷🏼utilisation des méthodes en L2
const marks = [...document.querySelectorAll("[data-mark]")]
.map(p => Number(p.dataset.mark));
const average =
marks.length ? (marks.reduce((a, b) => a + b) / marks.length).toFixed(2) : "Aucune note";
See the Pen
querySelector by dupont (@dupontcodepen)
on CodePen
Create element
Etude de la structure de l'application :
Code : https://github.com/dupontdenis/beautifullAnim.gitTOP anim : https://dupontdenis.github.io/animTrail/
Inscription à :
Commentaires (Atom)