Théorie: (16 Points)
*Exercice 1:
1-d
2-a
3-a
4-a
5-d
6-c
7-a
8-b
*Exercice 2:
function maxElement(arr) {
if ( || [Link] === 0) {
return undefined;
}
return [Link](...arr);
}
*Exercice 3:
Lorsque la souris passe au-dessus de l’image,
celle-ci est remplacée par "[Link]"
et le chemin est affiché dans le paragraphe.
Quand la souris quitte l’image,
celle-ci redevient "[Link]"
et le chemin est à nouveau affiché
dans le paragraphe.
Pratique : ( 24 Points )
1-function charger() {
const select = [Link]("listeLivres");
[Link]((livre, index) => {
const option = [Link]("option");
[Link] = index;
[Link] = [Link];
[Link](option);
});
afficher();
}
2-function afficher() {
const index = [Link]("listeLivres").value;
const livre = livres[index];
[Link]("titreLivre").textContent = [Link];
[Link]("prixLivre").textContent = [Link];
[Link]("imageLivre").src = [Link];
}
3-function ajouter() {
const index = [Link]("listeLivres").value;
const livre = livres[index];
[Link](livre);
total += [Link];
const li = [Link]("li");
[Link] = `${[Link]} - ${[Link]} Dhs`;
[Link]("data-index", index);
[Link]("panier").appendChild(li);
[Link]("total").textContent = total;
}
4-function retirer() {
const select = [Link]("listeLivres");
const index = [Link];
const ul = [Link]("panier");
const items = [Link]("li");
for (let i = 0; i < [Link]; i++) {
if (items[i].getAttribute("data-index") === index) {
[Link](items[i]);
total -= livres[index].prix;
[Link]("total").textContent = total;
[Link](i, 1);
break;
}
}
}
5-<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Librairie Informatique</title>
</head>
<body onload="charger()">
<h2>Liste des livres</h2>
<select id="listeLivres" onchange="afficher()"></select>
<div id="infoLivre" style="margin-top: 10px;">
<p><strong>Titre :</strong> <span id="titreLivre"></span></p>
<p><strong>Prix :</strong> <span id="prixLivre"></span> Dhs</p>
<img id="imageLivre" src="" alt="Image du livre" width="100">
</div>
<button onclick="ajouter()">Ajouter au panier</button>
<button onclick="retirer()">Retirer du panier</button>
<h2>Panier</h2>
<ul id="panier"></ul>
<p><strong>Total :</strong> <span id="total">0</span> Dhs</p>
<script>
const livres = [
{"ISBN":"01234","titre":"Langage C","image":"[Link]","prix":150},
{"ISBN":"56789","titre":"Programmation
Javascript","image":"[Link]","prix":250},
{"ISBN":"11778","titre":"Laravel","image":"[Link]","prix":200}
];
let panier = [];
let total = 0;
function charger() {
const select = [Link]("listeLivres");
[Link]((livre, index) => {
const option = [Link]("option");
[Link] = index;
[Link] = [Link];
[Link](option);
});
afficher();
}
function afficher() {
const index = [Link]("listeLivres").value;
const livre = livres[index];
[Link]("titreLivre").textContent = [Link];
[Link]("prixLivre").textContent = [Link];
[Link]("imageLivre").src = [Link];
}
function ajouter() {
const index = [Link]("listeLivres").value;
const livre = livres[index];
[Link](livre);
total += [Link];
const li = [Link]("li");
[Link] = `${[Link]} - ${[Link]} Dhs`;
[Link]("data-index", index);
[Link]("panier").appendChild(li);
[Link]("total").textContent = total;
}
function retirer() {
const select = [Link]("listeLivres");
const index = [Link];
const ul = [Link]("panier");
const items = [Link]("li");
for (let i = 0; i < [Link]; i++) {
if (items[i].getAttribute("data-index") === index) {
[Link](items[i]);
total -= livres[index].prix;
[Link]("total").textContent = total;
[Link](i, 1);
break;
}
}
}
</script>
</body>
</html>