Ask coding questions

← Back to all posts
JS Assignment 13: Intro to Classes in Javascript
maximussallam (3)

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,
this.username = name;
// Set the value of password to pw,
this.passwod = pw;
// Set the value of email to mail
this.email = mail;
// Set the value of checkPassword to a function.
this.checkPassword = 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.

}

What am I missing in the function?

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

Your checkPassword function needs to accept a string as an input, and compare it to the password. It would look something like so:

checkPassword = function(stringInput){return stringInput == this.password}

Any questions about the code?

maximussallam (3)

@a5rocks aaahhhhh!!!! I was really close on this one. I see where I was going wrong now. All my attempts at completing this function were just slightly off. Thank you so much for your assistance. I really appreciate you!

maximussallam (3)

@a5rocks Unfortunately, I'm getting this error: Expected undefined to be 'abc123'.

I have this in the repl:

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.
this.username = name;
this.passwod = pw;
this.email = mail;
checkPassword = function(string){
return string === this.password;
};
}

vedprad1 (692)

@maximussallam : You spelled password wrong.
If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!

maximussallam (3)

@vedprad1 after correcting the misspelling, I'm getting this error: Expected 'undefined' to be 'function'.

a5rocks (506)

@maximussallam oh sorry I was offline... this.checkPassword instead of checkPassword... Sorry my mistake.

maximussallam (3)

@a5rocks That worked! Thank you!