Nadszedł czas, by uruchomić całą flotę samochodów. Dodaj metodę drive do każdego z obiektów
samochodów. Kiedy już się z tym uporasz, dodaj kod, który dla każdego samochodu uruchomi silnik,
przejedzie się trochę, a następnie wyłączy silnik. Poniżej znajdziesz nasze rozwiązanie.
Ćwiczenie
Rozwiązanie
var cadi = {
make: ”GM”,
model: ”Cadillac”,
year: 1955,
color: ”jasnobrÈzowy”,
passengers: 5,
convertible: false,
mileage: 12892,
started: false,
start: function() {
this.started = true;
},
stop: function() {
this.started = false;
},
drive: function() {
if (this.started) {
alert(this.make + ” ” +
this.model + ” robi: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.