JSFiddle - React, Tailwind, and code Playground
JavaScript
class Car {
constructor(make, model){
this.make = make;
this.model = model;
this.userGears = ["P", "R", "N", "D"];
this.userGear = this.userGears[0];
}
shift(gear){
if(this.userGears.indexOf(gear) < 0)
throw new Error(`Wrong gear: ${gear}`);
this.userGear = gear;
}
}
const whip = new Car("Dodge", "Viper");
whip.shift("D");
console.log(whip);