The task:
declare a variable called myName that returns an array of two elements, firstname and last name.
declare a function called join(), it will return the two elements as a string with a space between each element.
declare a function createProfile that should expect an array "name" as input(???).
createProfile creates and returns an object with two key-value pairs. key: name value: use the function "join()" and the parameter "name" variable to return a string with your full name, separated by a space
key
: emailvalue
: my email as a string.Declare a variable called myProfile and assign the result of calling createProfile with myName.
The problem is in step 4. I believe I should use an object constructor. I don't know how to properly include the function join() a value in a key-value pair in an object constructor.
Here is what I have tried so far:
const myName = ["firstname", "lastname"];
function join(){
document.write("Hello, my name is " + myName[0] + " " + myName[1] + ".");
};
join();
function createProfile(name, email){
this.name = function(){
return this.join();
};
this.email = email;
return this;
}
let myProfile = new createProfile(name,"me@gmail.com");
console.log(myProfile);
Expected results: calling create profile should log an object with my full name as a string, and my email address as a string.
Actual results:
createProfile {name: ƒ, email: "hotcoffeehero@gmail.com"}
email: "hotcoffeehero@gmail.com"
name: ƒ ()
__proto__: Object
The value of name is an empty function.
How do I display it as a string?
Onegai Shimasu