From 0264f704b2df84d4dcb4e24b7db0692888f9d5b3 Mon Sep 17 00:00:00 2001 From: Celia Antunes Date: Fri, 16 Feb 2024 15:05:33 +0100 Subject: [PATCH] evla celia antunes --- index.html | 18 ++++++++++++++++-- js/car.js | 37 +++++++++++++++++++++++++++++++++++++ js/extra.js | 6 ++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 js/car.js create mode 100644 js/extra.js diff --git a/index.html b/index.html index be6da78..ac51c3b 100644 --- a/index.html +++ b/index.html @@ -32,19 +32,33 @@ + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000..5d2c305 --- /dev/null +++ b/js/car.js @@ -0,0 +1,37 @@ +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.tabExtras = 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.tabExtras.length; i++ ) + { + const extra = document.createElement ( "li" ); + extra.textContent = this.tabExtras[i].name + " " + this.tabExtras[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..01d35a0 --- /dev/null +++ b/js/extra.js @@ -0,0 +1,6 @@ +function Extra (name, price ) +{ + this.name = name; + this.price = price; +} + -- GitLab