From e8adf63a7d833d64dc27c6d1051792b1fe4e4050 Mon Sep 17 00:00:00 2001 From: Sacha BALTIDE Date: Fri, 16 Feb 2024 14:54:21 +0100 Subject: [PATCH 1/2] code sacha baltide --- index.html | 20 ++++++++++++++++++-- js/car.js | 31 +++++++++++++++++++++++++++++++ js/extra.js | 6 ++++++ js/index.js | 1 + 4 files changed, 56 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..822ce11 100644 --- a/index.html +++ b/index.html @@ -32,17 +32,33 @@ + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000..832680f --- /dev/null +++ b/js/car.js @@ -0,0 +1,31 @@ +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 = []; + +} + + +Car.prototype.generateImage = function(elt) { + var img = document.createElement("img"); + img.src = this.image; + img.alt = this.make + " " + this.model; + img.className ="card-img-top" + elt.appendChild(img); +} + +Car.prototype.generateExtra = function(elt) { + var ul = document.createElement("ul"); + elt.appendChild(ul); + for (var i = 0; i < this.extras.length; i++) { + var li = document.createElement("li"); + li.textContent = this.extras[i]; + ul.appendChild(li); + } +} \ No newline at end of file diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000..4c53e5c --- /dev/null +++ b/js/extra.js @@ -0,0 +1,6 @@ +function Extra(name, price) { + this.name = name; + this.price = price; + +} + diff --git a/js/index.js b/js/index.js index 4e1d119..6d7f5e7 100644 --- a/js/index.js +++ b/js/index.js @@ -1,3 +1,4 @@ + const extraList = [ { name: "Jantes alliage", price: 500 }, { name: "Toit ouvrant", price: 1000 }, -- GitLab From 4096e1904a62ba73a58b6c136c8a873999f0c0ef Mon Sep 17 00:00:00 2001 From: Sacha BALTIDE Date: Fri, 16 Feb 2024 15:22:20 +0100 Subject: [PATCH 2/2] code sacha baltide --- index.html | 2 +- js/car.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 822ce11..be8ee78 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@ car.generateExtras(elt); } else { btn.innerHTML = "+"; - elt.innerHTML = ""; + elt.innerHTML = " "; } } diff --git a/js/car.js b/js/car.js index 832680f..a64fdf3 100644 --- a/js/car.js +++ b/js/car.js @@ -7,7 +7,7 @@ function Car(image,make,model,description,price,category,year,mileage,extras) { this.category = category; this.year = year; this.mileage = mileage; - this.extras = []; + this.extras = extras; } @@ -20,7 +20,7 @@ Car.prototype.generateImage = function(elt) { elt.appendChild(img); } -Car.prototype.generateExtra = function(elt) { +Car.prototype.generateExtras = function(elt) { var ul = document.createElement("ul"); elt.appendChild(ul); for (var i = 0; i < this.extras.length; i++) { -- GitLab