diff --git a/index.html b/index.html index be6da78c5e9ec9f23846a724d7820f71b1816897..f565b7537210c607169fd337e6f1e028a2704a8e 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - Page Title + Voitures @@ -32,17 +32,32 @@ + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000000000000000000000000000000000000..8fd2c883c0797ff882fca04c9a2c50409bc52753 --- /dev/null +++ b/js/car.js @@ -0,0 +1,36 @@ +// Définition du prototype Car +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 imgElement = document.createElement('img'); + imgElement.src = this.image; + imgElement.alt = this.make + " " + this.model; + imgElement.classList.add('card-img-top'); + + elt.appendChild(imgElement); +} + +Car.prototype.generateExtras = function(elt) { + var ulElement = document.createElement('ul'); + + this.extras.forEach(function(extra) { + var liElement = document.createElement('li'); + var extraText = extra.name + ' - ' + extra.price; + var textNode = document.createTextNode(extraText); + liElement.appendChild(textNode); + ulElement.appendChild(liElement); + }); + + elt.appendChild(ulElement); +} + diff --git a/js/extra.js b/js/extra.js new file mode 100644 index 0000000000000000000000000000000000000000..b78279a95a6251091cefff8dc48620328e1bf5ee --- /dev/null +++ b/js/extra.js @@ -0,0 +1,5 @@ +// Définition du prototype Extra +function Extra(name, price) { + this.name = name; + this.price = price; + } \ No newline at end of file