function calculateAverageYearlyWorks(numberOfWorks, bornYear, deathYear) {
  var age = deathYear - bornYear;
  var avg = numberOfWorks / age;

  return avg;
}

var artists = []; // zaczynamy od pustej tablicy

artists.push({
  name: "Pablo Picasso",
  bornYear: 1881,
  deathYear: 1973,
  numberOfWorks: 50000
});

artists.push({
  name: "Leonardo Da Vinci",
  bornYear: 1452,
  deathYear: 1519,
  numberOfWorks: 30
});

artists.push({
  name: "Claude Monet",
  bornYear: 1840,
  deathYear: 1926,
  numberOfWorks: 2500
});

for (var i = 0; i < artists.length; i = i + 1) {
  var avgYearlyWorks = calculateAverageYearlyWorks(artists[i].numberOfWorks, artists[i].bornYear, artists[i].deathYear)
      
  document.body.innerText = document.body.innerText 
    + artists[i].name 
    + " zmarł w wieku " 
    + (artists[i].deathYear - artists[i].bornYear) 
    + " lat, średnio roczne stworzył " 
    + avgYearlyWorks
    + " dzieł sztuki."
  
  if (avgYearlyWorks > 1) {
    document.body.innerText = document.body.innerText + " Artysta tworzył więcej niż jedno dzieło rocznie!";
  }
  
  document.body.innerText = document.body.innerText + "\n";
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.