Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
class Car {
  constructor(make, model) {
    this._make = make
    this._model = model
    this._miles = 30
  }
  get make() {
    return this._make
  }
  get model() {
    return this._model
  }
  get miles() {
    return this._miles
  }
  set model(newModel) {
    this._model = newModel
  }
  drive(newMiles) {
    console.log(`driving ${newMiles} miles`)
    this._miles = this._miles + newMiles
  }
}
const myTesla = new Car("Telsa", "Model 3")
console.log(myTesla.make)
console.log(myTesla.miles)
// call instance.addMilage() method
// to add additional miles
myTesla.drive(15)
myTesla.drive(7)
console.log(myTesla.miles)
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x