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 Animal {
  constructor(name, weight) {
    this._name = name
    this._weight = weight
  }
  eat() {
    return `${this._name} is eating!`
  }
  sleep() {
    return `${this._name} is going to sleep!`
  }
  wakeUp() {
    return `${this._name} is waking up!`
  }
}  
class Gorilla extends Animal {
  constructor(name, weight, height) {
    super(name, weight)
    // property not shared with Animal class
    this._height = height
  }
  get height() {
    return this._height
  }
  climbTrees() {
    return `${this._name} is climbing trees!`
  }
  poundChest() {
    return `${this._name} is pounding its chest!`
  }
  showVigour() {
    return `${this.eat()} ${this.poundChest()}`
  }
  dailyRoutine() {
    return `${this.wakeUp()} ${this.poundChest()} ${this.eat()} ${this.sleep()}`
  }
}
const gorilla = new Gorilla('George', '160Kg', '6ft')
console.log(gorilla.eat())
console.log(gorilla.poundChest())
console.log(gorilla.sleep())
console.log(gorilla.height)
console.log(gorilla.dailyRoutine())
Output

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

Dismiss x