javascript - JS Objects and Functions Corrections -


i've got homework assignment correct javascript code preventing functions being executed. i've corrected can find, used jsfiddle , jshint make sure. there's no syntax errors left, there must logic error because nothing working. i'd appreciate quick @ code, i'm sure it's minor issue i'm overlooking. thanks!

(there's bound messy code here how many things i've tried change around, apologies that).

first basic html:

<body> <p id="message"></p> <p id="movies"></p> <p id="object"></p> </body> 

then js:

// define variables var output = document.getelementbyid("message"); var br = "<br>"; var makebreakfast; var mood; var energylevel; var dowork; var poweron; var command; var duration; var quitwork;  // define robot object var robot = { material: "titanium", mood: "happy", energylevel: 100, poweron: false, command: "sweeping floor", duration: 10, favoritemovies: ["2001: space odyssey", "the terminator", "i, robot",        "wall-e", "short circuit", "forbidden planet"] };   makebreakfast = function (newmood) { mood = newmood; if (mood === "happy") {     output.innerhtml += "here waffles , milk, master." + br; } else {     output.innerhtml += "here burnt toast , lukewarm water,    master." + br;     energylevel = 50; } }; dowork = function () { if (!poweron) {     poweron = true;     output.innerhtml += "my current task is: " + command + ". duration: " +     duration + " minutes." + br; } }; quitwork = function () { if (poweron) {     energylevel = 90;     poweron = false;     command = "taking nap"; } };  // make robot housework dowork(); quitwork(); 

the full assignment follows: 1) correct code, , make dowork , quitwork execute properly. 2) call makebreakfast argument , use string "mad" argument. 3) add new method , call display string (left part out, not helpful right now) 4) list of robots favorite movies, each on new line. 5) use named indexing syntax add new property called language robot object. initialize language of choice. 6) using named indexing syntax, loop through object , list each of property , value pairs on new line. display results in new paragraph.

i wanted #1, if seeing full assignment helps, it. everyone!

need make object, , tell poor schmuck make breakfast!

(full difference)

// define variables  var output = document.getelementbyid("message");  var movies = document.getelementbyid("movies");  // define variables  var output = document.getelementbyid("message");  var movies = document.getelementbyid("movies");  var object = document.getelementbyid("object");  var br = "<br>";    // define robot object  var robot = {      material: "titanium",      mood: "happy",      energylevel: 100,      poweron: false,      command: "sweeping floor",      duration: 10,      favoritemovies: ["2001: space odyssey", "the terminator", "i, robot", "wall-e", "short circuit", "forbidden planet"],            makebreakfast: function (newmood) {          if(newmood) this.mood = newmood;          this.command = "making breakfast";          this.dowork();          if (this.mood === "happy") {              output.innerhtml += "here waffles , milk, master." + br;          } else {              output.innerhtml += "here burnt toast , lukewarm water,    master." + br;              this.energylevel = 50;          }      },      dowork: function () {          if(!this.poweron) {              this.poweron = true;              output.innerhtml += "my current task is: " + this.command + ". duration: " + this.duration + " minutes." + br;          }      },      quitwork: function () {          if (this.poweron) {              this.energylevel = 90;              this.poweron = false;              this.command = "taking nap";              output.innerhtml += "my current task is: " + this.command + ". duration: " + this.duration + " minutes." + br;          }      }  };    // make robot housework  robot.dowork();  robot.quitwork();  robot.makebreakfast();  robot.quitwork();  robot.makebreakfast("mad");  robot.quitwork();
<body>      <p id="message"></p>      <p id="movies"></p>      <p id="object"></p>  </body>


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -