From 3b549734b98c999db20d13897a67cb9165142623 Mon Sep 17 00:00:00 2001 From: Maxime Lemoine Date: Fri, 16 Feb 2024 14:50:15 +0100 Subject: [PATCH] ajout des voitures --- index.html | 25 ++++++++++++++++++++----- js/car.js | 36 ++++++++++++++++++++++++++++++++++++ js/extra.js | 5 +++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 js/car.js create mode 100644 js/extra.js diff --git a/index.html b/index.html index be6da78..9394f3b 100644 --- a/index.html +++ b/index.html @@ -32,18 +32,33 @@ + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000..2badd52 --- /dev/null +++ b/js/car.js @@ -0,0 +1,36 @@ +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 div = document.getElementById( "app" ); + + const img = document.createElement( "img" ); + img.src = this.image; + img.alt = this.make + "-" + this.model; + img.className = "card-img-top"; + + elt.appendChild( img ); +} + +Car.prototype.generateExtras = function( elt ) { + const ul = document.createElement( "ul" ); + ul.className = "extras"; + + for ( let i = 0; i < this.extras.length; i++ ) { + const li = document.createElement( "li" ); + li.textContent = this.extras[i].name + " : " + this.extras[i].price; + ul.appendChild( li ); + } + + 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..e0a38e3 --- /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