diff --git a/index.html b/index.html index be6da78c5e9ec9f23846a724d7820f71b1816897..9394f3bec44c5db8a34bb62faa028189bd0ca9d2 100644 --- a/index.html +++ b/index.html @@ -32,18 +32,33 @@ + + diff --git a/js/car.js b/js/car.js new file mode 100644 index 0000000000000000000000000000000000000000..2badd5234dad12d3290df7c01797f97de847ca86 --- /dev/null +++ b/js/car.js @@ -0,0 +1,36 @@ +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 ) { + const div = document.getElementById( "app" ); + + const img = document.createElement( "img" ); + img.src = this.image; + img.alt = this.make + "-" + this.model; + img.className = "card-img-top"; + + elt.appendChild( img ); +} + +Car.prototype.generateExtras = function( elt ) { + const ul = document.createElement( "ul" ); + ul.className = "extras"; + + for ( let i = 0; i < this.extras.length; i++ ) { + const li = document.createElement( "li" ); + li.textContent = this.extras[i].name + " : " + this.extras[i].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..e0a38e3d80b6da0f48539d3b35864e101c698c58 --- /dev/null +++ b/js/extra.js @@ -0,0 +1,5 @@ +function Extra( name, price ) +{ + this.name = name; + this.price = price; +} \ No newline at end of file