Untitled

 avatar
unknown
javascript
10 months ago
408 B
12
Indexable
const ogrenci = {
  ad: "Ömer",
  soyad: "Orhan",
  notlar: [74, 98],

  ortalamaHesapla: function() {
    if (this.notlar.length === 0) {
      return 0;
    }
    const toplam = this.notlar.reduce((acc, not) => acc + not, 0);
    return toplam / this.notlar.length;
  }
};

const ogrenciOrtalamasi = ogrenci.ortalamaHesapla();
console.log(`Ogrencinin not ortalamasi: ${ogrenciOrtalamasi}`);
Editor is loading...
Leave a Comment