DEV Community

Cover image for Class basic syntax
hannaA
hannaA

Posted on

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

Top comments (0)