简体   繁体   中英

When I run this code I'm not getting any output, any advice or correction please

What's wrong with this code I'm getting undefined as output.

function ClassOne(name, pw, mail){
      // Exercise One: In this exercise you will be creating your own class!
      // You are currently in the class, you are given three strings, name, pw, and mail.
      // You need to create three properties on this class.
      // Those properties are: 'username', 'password', and 'email'
      // Set the value of username to name,
      // Set the value of password to pw,
      // Set the value of email to mail

    this.ursername = name;
    this.password = pw;
    this.email = mail;


      // Note: Remember you DO NOT need to return anything in a class!
    }

    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 (string) {

    return `${this.password}`;

      }
    }


// This code below output the first exercise which was ok but the second exercise is not showing any output.

 function exerciseOne(){
  // Exercise One: In this exercise you are given an object called 'mathHelpers'
  // Within mathHelpers, create a method called 'double'
  // This method should take one parameter, a number, 
  // and it should return that number multiplied by two.
  let mathHelpers = {
    // Create double method in here.
    double: function(number){
      return number * 2;
    }
  };
  return mathHelpers;
}

function exerciseTwo(userObj){
// Exercise Two: You will be given an object called 'userObj'
// userObject will already have a key on it called 'name'
// Add a method to userObj, called 'greeting'.
// Using the keyword 'this', the greeting method should return the following string:
// 'Hi, my name is ' and the users name.
// eg: If userObj has a name: 'Dan', greeting should return: Hi, my name is Dan'
// NOTE: DO NOT create a new object.
// NOTE: DO NOT create a key called name the key is already on the object.
userObj = {

greeting:function() {
return `Hi, my name is: ${this.username}`;
   }
};

  // Please write all of your code on the lines above.

}

greeting:function() { return Hi, my name is: ${this.username} ; } };

// Please write all of your code on the lines above.

}

the problem is that the greeting function needed to be created on the userObj.

userObj.greeting = function() {

return Hi, my name is: ${this.username} ;

}

this.password need to be true.

so it should be

return this.password === string or return this.password === newPassword

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM