Make a Person- Code working in text editor but not on fcc

Make a Person- Code working in text editor but not on fcc
0

#1

Tell us what’s happening:
In my text editor (webstorm) every test case is passing but not on fcc. When I refresh the page using f5 after putting my code…every test case is green…but after that when I click “Run Tests” some test do not pass. I do not understand why?

Your code so far


const Person = function(firstAndLast) {
    // Complete the method below and implement the others similarly
    this.getFullName = function() {
        return firstAndLast;
    };
    this.getFirstName = function(){
        const regExp = /\w+(?=\s)/;
        const firstName = firstAndLast.match(regExp)[0];
        return firstName;
    };
    this.getLastName = function () {
        const regExp = /(?<=\s)\w+/;
        const lastName = firstAndLast.match(regExp)[0];
        return lastName;
    };
    this.setFirstName = function (first) {
        const regExp = /\w+(?=\s)/;
        firstAndLast = firstAndLast.replace(regExp,first);
    };
    this.setLastName = function(last){
        const regExp = /(?<=\s)\w+/;
        firstAndLast = firstAndLast.replace(regExp,last);
    };
    this.setFullName = function (fullName) {
        firstAndLast = fullName;
    };
};


const bob = new Person('Bob Ross');

bob.getFullName();

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36.

Link to the challenge:


#2

Replace
const Person = function(firstAndLast) {
with
var Person = function(firstAndLast) {

and
const bob = new Person('Bob Ross');
with
var bob = new Person('Bob Ross');


#3

Okay, that worked but I did not understand why?

  1. Can i use let instead of var?
  2. Even if I use const, why isn’t my code being accepted?

#4
  1. No.
  2. It’s related to how FCC run tests.
    If you open the console with your original code, you’ll see errors: “x has already been declared”