Ask coding questions

← Back to all posts
JS Assignment 14 The Class Prototype
Exit (2)

I’m having difficulty understanding how to solve the second exercise. I watched and read through the lesson, but can’t find where it teaches to add a method to a prototype.
Any help would be wonderful
https://repl.it/student/submissions/7128534

Commentshotnewtop
Oluwiz (0)

Hi @Exit, just in case you still haven't found the solution.

You can just do this:

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

heyitsmarcus (284)

It looks like there is one major error where you're missing a + on this line:

this.speak = name + 'says' noise;

Change to:

//You need a + between 'says' and noise
//But also, you'll likely need the extra spaces in ' says ' because otherwise 
//the sentence will be jumbled together instead of evenly spaced as it 
//should be
this.speak = name + ' says ' + noise;

Or, in the latest JavaScript syntax:

//The newest syntax makes it easier to see what the sentence will look like
//when it is returned
this.speak = `${name} says ${noise}`;

If this solved your problem, please consider marking my answer as the accepted answer to close this question. If you have any further questions on this, I'll answer those still.

heyitsmarcus (284)

Hey @Exit, you'll have to post your code into a new repl, and then post the link here. We can't see your submissions in a classroom.