I have been trying to make this work for days but just can't seem to find any solution to it! I have completed the entire JS tutorial on codecademy and it is still baffling me!
Complete the program below such that the output is the same as that shown below. Taxi objects should inherit color
, numWheels
, and blowHorn
from Vehicle.
The code I am given is as follows
for(var i=0; i<5; i++) {
fleet[i] = new Taxi(i);
}
for (var i=0;i<fleet.length;i++) {
print("Taxi with badge number " + fleet[i].badgeNumber + " is " + fleet[i].color);
}
??????????????? = "White";
for ( var i=0; i<fleet.length; i++) {
print("Taxi with badge number " + fleet[i].badgeNumber + " is " + fleet[i].color);
fleet[i].blowHorn();
}
And it should print out this when completed:
Taxi with badge number 0 is yellow
Taxi with badge number 1 is yellow
Taxi with badge number 2 is yellow
Taxi with badge number 3 is yellow
Taxi with badge number 4 is yellow
Taxi with badge number 0 is White Beep!
Taxi with badge number 1 is White Beep!
Taxi with badge number 2 is White Beep!
Taxi with badge number 3 is White Beep!
Taxi with badge number 4 is White Beep!
I guess you don't know how to implement that part:
??????????????? = "White";
The most efficient way to do this is to update/change the color value inside the loop. Because you already iterate over each element in the array. So doing this again makes no sense. Just add
fleet[i].color = "White";
After the print in the first for loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.