Skip to content
Advertisement

Program not printing element at index 0

I’m working on case 3 and I need to print some details about the 3 instances for the Airplane class and the BatMobile class. The loop only prints out elements at index 1 and 2 and the other 3 instances for the BatMobile class. Why is this happening and how can I print all 3 instances for both classes?

JavaScript

Advertisement

Answer

Since the array is initialized with null values the first time you run

JavaScript

it returns false and runs vehicles_Instances() which fills the array but then the for loop increments so it will print index 1.

so just run vehicles_Instances(); before the for loop

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement