Menu
Coddy logo textTech

Akıllı Ev Cihaz Sistemi

Coddy'nin JavaScript Journey'sinin Nesne Yönelimli Programlama bölümünün bir parçası — ders 56 / 56.

challenge icon

Görev

Bu meydan okumada, akıllı evimizde kaç cihaz olduğunu izleyebilmemiz için SmartDevice sistemine statik izleme eklemeniz gerekiyor.

1. SmartDevice sınıfına statik özellik ekleyin:

  • Sınıfın en üstüne şunu ekleyin: static totalDevices = 0;

2. Yapıcı metot (constructor) içinde sayacı artırın:

  • SmartDevice yapıcısında şunu ekleyin: SmartDevice.totalDevices++;

3. Sayıyı almak için statik metot ekleyin:

  • Şunu ekleyin: static getDeviceCount() { return SmartDevice.totalDevices; }

Kendin dene

import { SmartDevice } from './device.js';

console.log(`Device count: ${SmartDevice.getDeviceCount()}`); // 0 olmalı

const basicDevice1 = new SmartDevice('Smart Plug');
const basicDevice2 = new SmartDevice(' Thermostat');
console.log(`Total devices now: ${SmartDevice.getDeviceCount()}`); // 2 olmalı

Nesne Yönelimli Programlama bölümündeki tüm dersler