When inserting a function in the browser console an error is generated and I can't figure out what the error is. The situation is the following
const sayHello = function(){
let greetingMsg = "Greetings ";
function msgTo(firstName, lastName){
greetingMsg = greetingMsg + firstName + " " + lastName;
}
return {
sendGreeting: function(firstName, lastName){
msgTo(firstName, lastName);
}
getMsg: function(){
return greetingMsg;
}
}
}
const createMsg = sayHello();
createMsg.sendGreeting(("Professor" , "Falken");
console.log(creatMsg.getMsg());
I would like to know where is the error to understand the function more clearly
I found at least two bugs that need to be fixed.
First, that when you create the constant
const createMsg
, then you call it with another name in theconsole.log(creatMsg.getMsg());
.Keep in mind to use the names of the variables well. I would recommend that you copy and paste them when reusing them to avoid such errors.
Next, another thing you missed is adding a comma between the
sendGreeting
and propertygetMsg
.When declaring an object in JavaScript, always separate its properties by commas.
Making those corrections, the code would look like this: