Ask coding questions

← Back to all posts
nothing i do works, 2 days ive been trying #14precourse exercise 1 prototypes
Jayese (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
this.UserClass = userclass;

UserClass.prototype.greeting = function(){

}

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

Commentshotnewtop
vedprad1 (732)

You should check resources online, like w3schools.com, before posting your question here. Anyways, here is the answer:

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

The this.UserClass = userclass line makes no sense because you do not have a variable called userclass, nor do you have a property called UserClass.

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

malvoliothegood (185)

The code snippets don't make sense to me. You are given the following code, and it looks to me that in the function body you just have to return 'Hello, it is nice to meet you!' (don't forget the semi-colon after the exclamation mark)

 UserClass.prototype.greeting = function(){
  // Return greeting here
}

I am confused by the following code. It looks to me as though it comes at the end of a function. If this is the case then maybe you have to create a function that you pass UserClass into, and in the function body you attach the greeting method to the class's prototype and then you return the class:

return UserClass
}

Where does this exercise come from? It seems a bit screwed to me and is not how I would teach JavaScript.