From 29f43c3f8fe2cd24ff0eb722b80b09f9c3fe0148 Mon Sep 17 00:00:00 2001 From: Alizea Lebaron Date: Fri, 16 Feb 2024 14:48:51 +0100 Subject: [PATCH] Lorem ipsum dolores sit ames --- index.html | 23 +++++++++++++++++++---- js/car.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ js/extra.js | 5 +++++ js/index.js | 43 +++++++++++++++++++++++++++++++------------ 4 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 js/car.js create mode 100644 js/extra.js diff --git a/index.html b/index.html index be6da78..d0e7604 100644 --- a/index.html +++ b/index.html @@ -32,16 +32,30 @@ + + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000..5db42ad --- /dev/null +++ b/js/car.js @@ -0,0 +1,49 @@ +function Car(image, make, model, description, price, category, year, mileage, extras) +{ + this.image = image ; + this.make = make ; + this.model = model ; + this.description = description; + this.price = price ; + this.category = category ; + this.year = year ; + this.mileage = mileage ; + this.extras = extras ; +} + +Car.prototype.generateImage = function(elt) +{ + //création de la balise image + const img = document.createElement(`img`); + + //ajout des propritété + img.src = "" + this.image; + img.alt = "" + this.make + this.model; + + img.classList.add("card-img-top"); + + //ajout de l'image à l'élément + elt.appendChild(img); +} + +Car.prototype.generateExtras = function (elt) +{ + //Création de la balise ul + const ul = document.createElement(`ul`); + + //Création des li (plus confortable pour dormir) + for (let i = 0; i < this.extras.length; i++) + { + //Création du li + const li = document.createElement(`li`); + + //Ajout du contenu de li + li.textContent= this.extras[i].name + " - " + this.extras[i].price + "€"; + + //Ajout du li au ul + ul.appendChild(li); + } + + //Ajout de ul à l'élément + elt.appendChild(ul); +} \ No newline at end of file diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000..c86905d --- /dev/null +++ b/js/extra.js @@ -0,0 +1,5 @@ +function Extra(name, price) +{ + this.name = name; + this.price = price; +} \ No newline at end of file diff --git a/js/index.js b/js/index.js index 4e1d119..90ce2aa 100644 --- a/js/index.js +++ b/js/index.js @@ -1,4 +1,5 @@ -const extraList = [ +const extraList = +[ { name: "Jantes alliage", price: 500 }, { name: "Toit ouvrant", price: 1000 }, { name: "Sièges chauffants", price: 400 }, @@ -12,8 +13,10 @@ const extraList = [ { name: "Peinture premium", price: 1000 }, ]; -const cars = [ - generateCar( +const cars = +[ + generateCar + ( "img/1.jpg", "Renault", "Clio", @@ -24,7 +27,9 @@ const cars = [ 10000, [extraList[0],extraList[3],extraList[4],extraList[6],extraList[8],extraList[9]] ), - generateCar( + + generateCar + ( "img/2.jpg", "Peugeot", "208", @@ -35,7 +40,9 @@ const cars = [ 5000, [extraList[2],extraList[3]] ), - generateCar( + + generateCar + ( "img/3.jpg", "Volkswagen", "Golf", @@ -46,7 +53,9 @@ const cars = [ 1000, [extraList[4],extraList[5]] ), - generateCar( + + generateCar + ( "img/4.jpg", "Ford", "Focus", @@ -57,7 +66,9 @@ const cars = [ 8000, [extraList[0],extraList[1]] ), - generateCar( + + generateCar + ( "img/5.jpg", "Citroën", "C4", @@ -68,7 +79,9 @@ const cars = [ 15000, [extraList[6],extraList[7]] ), - generateCar( + + generateCar + ( "img/6.jpg", "Toyota", "Yaris", @@ -79,7 +92,9 @@ const cars = [ 2000, [extraList[4],extraList[8]] ), - generateCar( + + generateCar + ( "img/7.jpg", "Hyundai", "Ioniq", @@ -90,7 +105,9 @@ const cars = [ 500, [extraList[0],extraList[1]] ), - generateCar( + + generateCar + ( "img/8.jpg", "Tesla", "Model 3", @@ -107,7 +124,8 @@ const app = document.getElementById('app'); let index = 0; let s = ""; -for (const car of cars) { +for (const car of cars) +{ if(car !== undefined) { index++; @@ -136,7 +154,8 @@ s += '' app.innerHTML = s index =0; -for (const car of cars) { +for (const car of cars) +{ if(car !== undefined) { index++; -- GitLab