Tell us what’s happening:
I found bits and pieces for the challenge by googling and stumbled through but the problem is that I don’t have the slightest idea how this constructors is supposed to be called to change the name from Bob Ross to anything else.
Neither do I understand how it does it in the set part.
The part with get is clear as it extracts the wanted part of the string given as argument but I can’t figure out how set part changes the name to something else.
I do understand all the set parts are functions that take an argument to process but how does any of those functions get the argument? How do I insert that argument into the constructor to make the “subfunctions” operate on the argument.
I have tried console.logging nearly everything that I came up with while also creating different function calls with different strings but I haven’t seen anything else been printed out than Bob Ross as stated in const bob = new Person(‘Bob Ross’);
Your code so far
const Person = function(firstAndLast) {
// Only change code below this line
// Complete the method below and implement the others similarly
let names = firstAndLast;
this.getFirstName = function() {
return names.split(" ")[0]
}
this.getLastName = function() {
return names.split(" ")[1]
}
this.getFullName = function() {
return names;
}
this.setFirstName = function(input) {
names = input + " " + names.split(" ")[1]
}
this.setLastName = function(input) {
names = names.split(" ")[0] + " " + input
}
this.setFullName = function(input) {
names = input
}
return firstAndLast;
};
const bob = new Person('Bob Ross');
console.log(bob.getFullName());
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Make a Person
Link to the challenge: