From 2edf253d1ee5222bbfc2d165e71e62c6da10c056 Mon Sep 17 00:00:00 2001 From: Capucine Lettier Date: Fri, 16 Feb 2024 14:56:14 +0100 Subject: [PATCH 1/2] capucine tp --- index.html | 23 ++++++++++++++++++++--- js/extra.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 js/extra.js diff --git a/index.html b/index.html index be6da78..f0a0ce2 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,9 @@ - Page Title + tp js + @@ -36,15 +37,31 @@ diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000..02326de --- /dev/null +++ b/js/extra.js @@ -0,0 +1,35 @@ + +function Extra(name, price) { + this.name = name; + this.price = price; +} + +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) { + let img = document.createElement("img"); + img.src = this.image; + img.classList.add("card-img-top"); + elt.appendChild(img); +} + +Car.prototype.generateExtras = function(elt) { + let ul = document.createElement("ul"); + for (const extra of this.extras) { + let li = document.createElement("li"); + li.textContent = extra.name+ "-" + extra.price; + ul.appendChild(li); + } + elt.appendChild(ul); +} \ No newline at end of file -- GitLab From 4bd29ce90ef7c93dd6b480bf8b4ab20cc0a4bfad Mon Sep 17 00:00:00 2001 From: Capucine Lettier Date: Fri, 16 Feb 2024 14:59:54 +0100 Subject: [PATCH 2/2] capucine tp --- js/extra.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/extra.js b/js/extra.js index 02326de..6c386d8 100644 --- a/js/extra.js +++ b/js/extra.js @@ -20,6 +20,7 @@ function Car(image, make, model, description, price, category, year, mileage, ex Car.prototype.generateImage = function(elt) { let img = document.createElement("img"); img.src = this.image; + img.alt = this.make + " " + this.model; img.classList.add("card-img-top"); elt.appendChild(img); } -- GitLab