let carName = "Porsche";
let carModel = "911 Targa";
let carColor = "white";

const startCar = name => {
    console.log(`${name} is starting`);
};

const helloCar = (name, model, color) => {
    const hello = `My car's name is ${name}, the model is ${model}, and the color is ${color}.`;
    console.log(hello);
};

const driveCar = name => {
    console.log(`${name} is driving`);
};

// Using the functions
startCar(carName); 
helloCar(carName, carModel, carColor); 
driveCar(carName);
// Car constructor function
function Car(name, model, color) {
    this.name = name;
    this.model = model;
    this.color = color;
}

// Define methods on the Car prototype
Car.prototype.start = function() {
    console.log(`${this.name} is starting`);
};

Car.prototype.introduce = function() {
    const message = `My car's name is ${this.name}, the model is ${this.model}, and the color is ${this.color}.`;
    console.log(message);
};

Car.prototype.drive = function() {
    console.log(`${this.name} is driving`);
};

// Example usage
let myCar = new Car("Porsche", "911 Targa", "white");

myCar.start();    // Output: "Porsche is starting"
myCar.introduce(); // Output: "My car's name is Porsche, the model is 911 Targa, and the color is white."
myCar.drive();    // Output: "Porsche is driving"
// Parent object declaration
function Animal() {
    this.name = "Animal";  // Property owned by the parent object (Animal)
}

// Adding a method to the parent object (Animal) via the prototype
Animal.prototype.say = function() {
    console.log("I am an animal.");
};

// Child object declaration
function Dog() {
    this.name = "Dog";
}

// Child object (Dog) inherits properties and methods from the parent object (Animal) using the prototype
Dog.prototype = new Animal();

// Using the parent’s properties and methods from the child (Dog) object
const myDog = new Dog();
console.log(myDog.name);  // Output: "Dog"
myDog.say();              // Output: "I am an animal."
function Animal(name) {
    this.name = name;
}

// Method shared by all objects created by Animal constructor
Animal.prototype.speak = function() {
    console.log(`Hello, my name is ${this.name}.`);
};

const dog = new Animal("Buddy");
dog.speak();  // Output: "Hello, my name is Buddy."
const parent = {
    sayHello: function() {
        console.log("Hello!");
    }
};

const child = Object.create(parent);
child.sayHello(); // Output: "Hello!"
class Animal {
    constructor(name) {
        this.name = name;
    }

    speak() {
        console.log(`${this.name} makes a sound.`);
    }
}

class Dog extends Animal { // Inherits from the Animal class using extends
    constructor(name, breed) {
        super(name); // Call the constructor of the parent class
        this.breed = breed;
    }

    bark() {
        console.log(`${this.name} barks.`);
    }
}

const myDog = new Dog("Buddy", "Retriever");
myDog.speak(); // Output: "Buddy makes a sound."
myDog.bark();  // Output: "Buddy barks."