Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an object graph to represent your favorite sports team, cast of movie cha

ID: 3563847 • Letter: C

Question

Create an object graph to represent your favorite sports team, cast of movie characters, or any other group of interesting objects. You must use a JavaScript CONSTRUCTOR to define object attributes, and to instanciate your objects. You must also use the JavaScript PROTOTYPE property to define and invoke at least one object function. When you are done, write an extremely simple HTML document to show the contents of your object graph. Don't forget to invoke at least one object function you defined in the class prototype. Your method of accessing the JavaScript objects to put them on the screen is irrelevant, I simply want to see a demonstrated understanding of JavaScript class definitions, instantiating objects, and invoking prototype functions.

Explanation / Answer

Save the text below line as html file

--------------------------------------------------------------------

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Object Graph</title>

<script type="text/javascript">

function MovieCast(movie, hero, villan){
  
   this.movie = movie;
   this.hero = hero;
   this.villan = villan;
  
   this.displayHero = function(){
       alert(hero);
   }
  
}

MovieCast.prototype.displayVillan = function(){
   alert(this.villan);
}


function show(){
   HarryPotter = new MovieCast("Harry Potter","Harry James Potter","Tom Riddle");
   HarryPotter.displayHero();
   HarryPotter.displayVillan();
}

</script>

</head>
<body>
<input type="button" value="click to alert" />
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote