Ask coding questions

← Back to all posts
1
IM getting error msg on my answerr? (jave script)
faziz6006 (2)

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


my code :

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

error msg i keep getting :
Should add a method to the prototype called speak

Commentshotnewtop
2
vedprad1 (461)

You can't say this.speak = says because you are in the middle of defining this.speak.
I don't think you need says as a parameter, too. Try this:

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

If this answer is correct, please check the checkmark on the left side of this message. Thanks and Good Luck!

1
theangryepicbanana (662)

do this.speak = says; instead of this.speak = 'says'; because 'says' is a string, but says gets the actual value of the parameter called says

1
faziz6006 (2)

@theangryepicbanana i changed it to :

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

still error : Should add a method to the prototype called speak