1
JS Assignment 14: The Class 'prototype'
Paultheriault (0)

function exerciseOne(UserClass){
// Exercise One: In this exercise you are given a class called UserClass.
// You will be adding a method to the prototype called greeting
// This method will return the string: 'Hello, it is nice to meet you!'
// DO NOT create a new class or object

// Please write your code in the lines above
return UserClass
}

function exerciseTwo(AnimalClass){
// Exercise Two: In this exercise you are given a class called AnimalClass.
// The class will already have the properties 'name', 'noise' on it.
// You will be adding a method to the prototype called 'speak'
// Using the 'this' keyword, speak should return the following string:
// '<name> says <noise>'
// DO NOT create a new class or object
AnimalClass.prototype.speak = function()
{
this.speak = name + 'says'; noise;
return this.speak ;
};

// Please write your code in the lines above
return AnimalClass;
}
I am having a hellacious time with these two, can I please get some assistance?

You are viewing a single comment. View All
1
vedprad1 (435)

Here are the answers. For more resources, check w3schools.com.

function exerciseOne(UserClass) {
  UserClass.prototype.greeting = function () {
    return 'Hello, it is nice to meet you!';
  };
}

function exerciseTwo(AnimalClass) {
  AnimalClass.prototype.speak = function () {
    return this.name + ' says ' + this.noise;
  };
}

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!