From 7e7f452d4a44b5523fc5456d4696567f33801b6e Mon Sep 17 00:00:00 2001 From: Frizoks Date: Fri, 16 Feb 2024 14:17:30 +0100 Subject: [PATCH 1/3] partie A --- js/car.js | 17 +++++++++++++++++ js/extra.js | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 js/car.js create mode 100644 js/extra.js diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000..bd40666 --- /dev/null +++ b/js/car.js @@ -0,0 +1,17 @@ +// Définition du prototype Car +function Car(image, make, model, description, price, category, year, mileage, []) { + 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; +} + +function generateCar(image, make, model, description, price, category, year, mileage, []) { + return new Car(image, make, model, description, price, category, year, mileage, []); +} + diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000..b78279a --- /dev/null +++ b/js/extra.js @@ -0,0 +1,5 @@ +// Définition du prototype Extra +function Extra(name, price) { + this.name = name; + this.price = price; + } \ No newline at end of file -- GitLab From 22f71565fa41943e139ec7218587e199c00f674d Mon Sep 17 00:00:00 2001 From: Frizoks Date: Fri, 16 Feb 2024 14:28:59 +0100 Subject: [PATCH 2/3] partie A qui marche mieux --- index.html | 8 +++++++- js/car.js | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index be6da78..bf6c3d6 100644 --- a/index.html +++ b/index.html @@ -32,12 +32,18 @@ + + diff --git a/js/car.js b/js/car.js index 3f77bfb..8fd2c88 100644 --- a/js/car.js +++ b/js/car.js @@ -11,3 +11,26 @@ function Car(image, make, model, description, price, category, year, mileage, ex this.extras = extras; } +Car.prototype.generateImage = function(elt) { + var imgElement = document.createElement('img'); + imgElement.src = this.image; + imgElement.alt = this.make + " " + this.model; + imgElement.classList.add('card-img-top'); + + elt.appendChild(imgElement); +} + +Car.prototype.generateExtras = function(elt) { + var ulElement = document.createElement('ul'); + + this.extras.forEach(function(extra) { + var liElement = document.createElement('li'); + var extraText = extra.name + ' - ' + extra.price; + var textNode = document.createTextNode(extraText); + liElement.appendChild(textNode); + ulElement.appendChild(liElement); + }); + + elt.appendChild(ulElement); +} + -- GitLab