Var not changing , Intermediate Algorithm Scripting: Make a Person

why str var is not getting changed ? its still bob ross

var Person = function(firstAndLast) {
  // Complete the method below and implement the others similarly
  var str = firstAndLast;

  this.getFullName = function() {
    return str;
  };
  this.getFirstName = function(){
    return str.split(" ")[0];
  };
  
  this.setFirstName =function(first){
    str = str.split(" ");
    str[0] = first;
    str = str.join(" ");
    //console.log(str);
  } 
this.getLastName = function(){
    return str.split(" ")[1];
  };
  this.getFullName= function(){
    return firstAndLast;
  }
  return firstAndLast;
};
var bob = new Person('Bob Ross');
console.log(bob.getFirstName());
bob.setFirstName("Haskell");
console.log(bob.getFullName());

You’re updating the str but returning firstAndLast which was never updated.

1 Like

I’m returning str , check full name function

it returns firstAndLast:

1 Like

In this function, you are returning firstAndLast instead of your modified variable of str. This will just return the original firstAndLast parameter that was given to the function

1 Like

Here. You’re return firstAndLast instead of str

1 Like

thanks, there were two functions with same name ,I was looking only at first one which returned str @ieahleen @crossphoton @Catalactics