Coding Problems!-JavaScript dated 16/03/2023

Hello everyone!
Today i am going to attach few coding problems. Please solve reply your answer.

  1. Create a class called Animal with a method called speak. Then, create two subclasses of Animal called Dog and Cat. Each subclass should implement its own speak method. Finally, create an array of Animal objects and call the speak method on each object.

  2. Create a function called calculate that takes two arguments, x and y, and performs a mathematical operation on them. The function should accept a third argument, operator, which specifies the operation to perform. The operator argument should be optional and default to +. The function should support addition, subtraction, multiplication, and division.

3.Create a class called Vehicle with a method called drive. Then, create two subclasses of Vehicle called Car and Truck. Each subclass should implement its own drive method. Finally, create an array of Vehicle objects and call the drive method on each object.

Have a Happy Learning

Thanks & Regards

Teaching Assistant,
Dharshini M.