DEV Community

Cover image for Class basic syntax
hannaA
hannaA

Posted on

2

Class basic syntax

user => first name and last name, return full name as a String

class User{
    constructor(name, lastName){
        this.name = name;
        this.lastName = lastName;
    }

    get fullName(){
        return this.name + " " + this.lastName;
    }
}

var user = new User("", "");
console.log(user.fullName);
Enter fullscreen mode Exit fullscreen mode

media => TvShows, movies, (episode, season), (duration)

class Media{
    constructor(name, year, imdb){
        this.name = name;
        this.year = year;
        this.imdb = imdb;
    }
}
    class Tvshows extends Media{
        constructor(name, year, imdb, episodes, seasons){
            super(name, year, imdb);
            this.episodes = episodes;
            this.seasons = seasons;
        }
    }

    class Movies extends Media{
        constructor(name, year, imdb, duration){
            super(name, year, imdb);
            this.duration = duration;
        }
    }

Enter fullscreen mode Exit fullscreen mode

find the mileage of the car

class Car {
    constructor (year) {
        this.year = year;
    }

     getAge(now){
        return now - this.year;
     }
}

let mini = new Car(2018)

console.log(mini.getAge(2022));
Enter fullscreen mode Exit fullscreen mode

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay