0

I have been working on this for days, and so far no luck. Every time I run this code I am being told that it was expected to be true (or false) depending on how I do the function.

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.password = pw,
  this.email = mail
  this.checkPassword = function checkPassword() {
    return this.password 
  }

  }
2
  • What have you tried, you only show the "class" where do you call it? What are you passing in for pw? Commented Mar 6, 2019 at 17:55
  • "Every time I run this code I am being told that it was expected to be true (or false) depending on how I do the function." can you elaborate? Commented Mar 6, 2019 at 17:56

4 Answers 4

2

You were missing the tested_pw argument to the checkPassword function

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.password = pw,
  this.email = mail
  this.checkPassword = function checkPassword(tested_pw) {
    return this.password === tested_pw
  }

  }
Sign up to request clarification or add additional context in comments.

Comments

0

This was my solution. I am a beginner with javascript but this worked for me.

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

Comments

0

Slow down and look at it; piece it together:

this.username = name;
this.password = pw;
this.email = mail;
this.checkPassword = function(str) {    
  if (this.password === str) {    
    return true;    
  }
  else (this.checkPassword !== this.password); {
    return false;
  }
};

Comments

0

you just need to read the instruction very carefully.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.