当我运行此代码时,我没有得到任何输出,任何建议或更正

时间:2019-11-10 13:55:32

标签: javascript

此代码有什么问题,我无法将其定义为输出。

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.

}

2 个答案:

答案 0 :(得分:0)

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

//请在上面的行中编写所有代码。

}

问题在于需要在userObj上创建问候语功能。

userObj.greeting = function(){

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

}

答案 1 :(得分:0)

此密码必须为真。

所以应该是

返回this.password ===字符串或返回this.password === newPassword