From 1965839b2470f1c0d3d2c84d270b7c7eca2f2dca Mon Sep 17 00:00:00 2001 From: Amaxi76 Date: Fri, 16 Feb 2024 14:43:06 +0100 Subject: [PATCH] =?UTF-8?q?Rendu=20du=20TP=20not=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 27 ++++++++++++++++++++++++--- js/car.js | 38 ++++++++++++++++++++++++++++++++++++++ js/extra.js | 5 +++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 js/car.js create mode 100644 js/extra.js diff --git a/index.html b/index.html index be6da78..c5964d9 100644 --- a/index.html +++ b/index.html @@ -32,22 +32,43 @@ + + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000..7ee715e --- /dev/null +++ b/js/car.js @@ -0,0 +1,38 @@ +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 ) +{ + const img = document.createElement ( "img" ); + + img.src = this.image; + img.alt = this.make + ' ' + this.model; + + img.classList.add ( 'card-img-top' ); + + elt.appendChild ( img ); +} + +Car.prototype.generateExtras = function ( elt ) +{ + const liste = document.createElement ( "ul" ); + + for ( let i = 0; i < this.extras.length; i++ ) + { + const extra = document.createElement ( "li" ); + extra.textContent = this.extras[i].name + " " + this.extras[i].price; + liste.appendChild ( extra ); + } + + elt.appendChild ( liste ); +} \ No newline at end of file diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000..1100295 --- /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 -- GitLab