Ask coding questions

← Back to all posts
Introduction to classes
poysed2code (2)

Can anyone help me with this question as I am stuck. The question is asking to set values in a class that was created one of which is set to a function("ceckPassword"). I am stuck at the part which asks to check if the new value ("checkPassword") is the same as an existing value (" password") and return true or false. Here's the question and my response:
function ClassTwo(name, pw, mail){
// Exercise Two: Now that you have created your own class,
// you will create a class with a method on it.
// In this class create 4 properties: username, password, email, and checkPassword.
// Set the value of username to name,
// Set the value of password to pw,
// Set the value of email to mail
// Set the value of checkPassword to a function.
// The checkPassword function takes a string as it's only argument.
// Using the 'this' keyword check to see if the password on the class is the same as
// the string being passed in as the parameter. Return true or false.
Here is my ateempt to answer:
this.username = name,
this.password = pw,
this.email = mail,
this.checkPassword = function(){

};
return this.password === this.checkPassword;

Answered by a5rocks (533) [earned 5 cycles]
View Answer
Commentshotnewtop
a5rocks (533)

I think maybe you should try returning this instead of this.password === this.checkPassword (which just checks if this.password is equal to this.checkPassword and returns true or false)

tl;dr

return this;
poysed2code (2)

@a5rocks I will let you know the outcome

wchamber01 (0)

Did you ever get this to work? I tried the a5rocks answer but it's not working for me.

SPQR (432)

could you link the repl rather than pasting the code?

poysed2code (2)

@SPQR I am not sure how to do that in repl.it

Steven_The_GuyT (204)

@poysed2code You copy paste the link of your repl into your description, or just paste your link into the box designated for your repl.