onlyforbopi
9/26/2018 - 8:02 AM

JS.Object.GameDesignwObjects.ex3

JS.Object.GameDesignwObjects.ex3

var darkVador = {
  race: 'human',
  job: 'villain',
  talk: function() {
    return 'come to the dark side, Luke!' + this.breathe();
  },
  describeYourself: function() {
    return "I'm a " + this.race + " and I'm a " + this.job + " in a series of movies!" + this.breathe();
  },
  breathe() {
    return ".....shhhhhhhhh.....";
  }
}

function dvSpeak() {
 document.body.innerHTML += '<p>Dark Vador describes himself: ' + darkVador.describeYourself(); + '</p>';  document.body.innerHTML += '<p>Dark Vador says: ' + darkVador.talk(); + '</p>';
}

JS.Object.GameDesignwObjects.ex3

A Pen by Pan Doul on CodePen.

License.


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>JavaScript OOP: methods</title>
  </head>
  <body>
    <button onclick='dvSpeak();'>Make Dark Vador speak!</button>
    </body>
</html>