01 workshops

by hxtpoe

HTML

<div id="app">

</div>

JavaScript

(function() {
	function CardComponent(product) {
  	this.product = product;
  }
  
  CardComponent.prototype.getDom = function() {
  	var div = document.createElement('div'),
    title  = document.createElement('h2'),
    box = document.createElement('div');
		title.textContent = this.product.name;
    box.textContent = this.product.description + '. Jest premium ' + this.product.premium;

    div.appendChild(title);
    div.appendChild(box);    
    
    return div;
  }

  function ListComponent(listName, listOfProducts) {
    this.listName = listName;
  	this.listOfProducts = listOfProducts;
  }

  ListComponent.prototype.getDom = function() {
  var div = document.createElement('div'),
    title  = document.createElement('h1'),
    box = document.createElement('div');
    
		title.textContent = this.listName;
    div.appendChild(title);
              
    this.listOfProducts.forEach(function(element) {
			 var myInstance = new CardComponent(element);
			 div.appendChild(myInstance.getDom());    
    });
        
    return div;  
  };
  //  
  var listOfCars = [
  	{
	  	name: "Audi 1",
      description: "Oto mój samochód",
      premium: true
  	},
    {
	  	name: "Merol 2",
      description: "Oto mój samochód",
            premium: true
  	},
    {
	  	name: "Ferrari 3",
      description: "Oto mój samochód 2",
      premium: true
  	},
    {
	  	name: "Maluch 3",
      description: "Oto mój samochód 2",
      premium: false
  	},
     {
	  	name: "Maluch 14898392839",
      description: "Oto mój maluch",
      premium: false
  	},
    {
	  	name: "Maluch 3",
      description: "Oto mój samochód 2fef",
      premium: false
  	},
     {
	  	name: "Maluch 14823239",
      description: "Oto mój malucffh",
      premium: false
  	}
  ];
  
  var app =  document.getElementById('app'),
  cache = document.createElement('div');
  
	var myListPremium = new ListComponent(
     "Lista promowanych ofert", 
     listOfCars.filter(function(e) { 
       return e.premium...