Class basic syntax

hannaha88

hannaA

Posted on July 30, 2022

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
💖 💪 🙅 🚩
hannaha88
hannaA

Posted on July 30, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related