diff --git a/img/9.jpg b/img/9.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cdf5f33521682899c881719d616495c59fd9b9f2 Binary files /dev/null and b/img/9.jpg differ diff --git a/index.html b/index.html index be6da78c5e9ec9f23846a724d7820f71b1816897..87fb944cfe83e2d85420557752e1bf41643093d4 100644 --- a/index.html +++ b/index.html @@ -38,16 +38,23 @@ function generateCar(image, make, model, description, price, category, year, mileage, extras) { //Create an array of Extra instances based on Extras names and prices // Create a new Car instance + return new Car(image, make, model, description, price, category, year, mileage, extras); } function showHideExtra(btn,elt,car) { + btn.innerText = btn.innerText === "-" ? "+" : "-"; + const childs = elt.children; + if (btn.innerText === "+") for (let i = childs.length - 1; i >= 0; i--) elt.removeChild(childs[i]); + else car.generateExtras(elt); } + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000000000000000000000000000000000000..80efc4a9e6a82cdcc8801fc4b8269e555ef72265 --- /dev/null +++ b/js/car.js @@ -0,0 +1,35 @@ +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) { + var 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) { + var ul = document.createElement("ul"); + + this.extras.forEach(e => { + var li = document.createElement("li"); + + li.innerText = e.name + " " + e.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 0000000000000000000000000000000000000000..d5f7ff9bd055aaff03a975e7372fe578b0c8ea21 --- /dev/null +++ b/js/extra.js @@ -0,0 +1,4 @@ +function Extra(name, price) { + this.name = name; + this.price = price; +} \ No newline at end of file diff --git a/js/index.js b/js/index.js index 4e1d11911c0a43dddf4d16bc89f1d2d5005e1fb2..3eeee6af7d92c2d68c95f873fda91de8a19f7e58 100644 --- a/js/index.js +++ b/js/index.js @@ -1,4 +1,4 @@ -const extraList = [ +const extraList = [ { name: "Jantes alliage", price: 500 }, { name: "Toit ouvrant", price: 1000 }, { name: "Sièges chauffants", price: 400 }, @@ -101,6 +101,17 @@ const cars = [ 1000, [extraList[9],extraList[10]] ), + generateCar( + "img/9.jpg", + "Ford Mustang Shelby", + "GT500", + "Voiture super sportive 3 portes, année 2023", + 27000, + "sportive", + 2023, + 4200, + [] + ), ]; const app = document.getElementById('app');