Tell us what’s happening:
Describe your issue in detail here.
Only the tests for “undefined” and “instanceof” are passing, none of the other tests are passing, and I’m not sure why. I have console.logged each function to figure out if they would give me what I asked for, and they did, but when I run the entire parent function, it does not pass any of the tests that require name-based answers…
Your code so far
const Person = function(firstAndLast) {
// Only change code below this line
function getFirstName(str) {
let strArr = str.split(" ");
return strArr[0];
}
function getLastName(str) {
let strArr = str.split(" ");
return strArr[1];
}
function getFullName(str) {
let strArr = str.split(" ");
return strArr.join(" ");
}
function setFirstName(first) {
return first;
}
function setLastName(last) {
return last;
}
function setFullName(firstAndLast) {
let strArr = firstAndLast.split(" ");
let first = strArr[0];
let last = strArr[1];
return first + " " + last;
}
// Complete the method below and implement the others similarly
this.getFullName = function() {
return "";
};
return firstAndLast;
};
const bob = new Person('Bob Ross');
bob.getFullName();
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Intermediate Algorithm Scripting - Make a Person
Tell us what’s happening:
Describe your issue in detail here.
Okay, I have re-worked my code, and more of the tests are passing, but about half of them are not. Somehow, the “Object.keys” test is no longer passing…not sure why that is. Also, all the “Haskell Curry” tests are not passing, when they were at first. So the passing tests have kind of flipped from my last code.
Your code so far
const Person = function(firstAndLast) {
// Only change code below this line
this.getFirstName = function () {
let fullName = firstAndLast;
let nameArr = fullName.split(" ");
return nameArr[0];
};
this.getLastName = function () {
let fullName = firstAndLast;
let nameArr = fullName.split(" ");
return nameArr[1];
};
this.getFullName = function () {
let fullName = firstAndLast;
return fullName
};
this.setFirstName = function (name) {
let fullName = firstAndLast;
fullNameArr = fullName.split(" ");
fullName = name + " " + fullNameArr[1];
};
this.setLastName = function (name) {
let fullName = firstAndLast;
fullNameArr = fullName.split(" ");
fullName = fullNameArr[0] + " " + name;
};
this.setFullName = function (name) {
// let fullName = firstAndLast;
fullName = name;
};
// Complete the method below and implement the others similarly
this.getFullName = function() {
return "";
};
return firstAndLast;
};
const bob = new Person('Bob Ross');
bob.getFullName();
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Challenge: Intermediate Algorithm Scripting - Make a Person
This all is an issue. You defined this method twice, and the second one isn’t going to work. Also, I don’t think you want to use return inside of the constructor?
ohhhh…I think I get it. It’s more of rearranging the code of the “get” functions to result in a reassignment…I’ll see what I can change to try and make it work. Thanks!
Okay, this is passing most of the tests, but some of them aren’t passing. Namely:
// not passing
bob.getFirstName() should return the string Bob.
// not passing
bob.getLastName() should return the string Ross.
// not passing
bob.getFullName() should return the string Bob Ross.
// not passing
bob.getFullName() should return the string Haskell Ross after bob.setFirstName("Haskell").
This is the current code and it should be passing…I checked several times for spelling and syntax errors, so I don’t think there are. But I finally kind of understood what was supposed to be happening here, so I have no idea why it’s not passing.
const Person = function(firstAndLast) {
// Only change code below this line
this.getFirstName = function () {
return firstAndLast.split(" ")[0];
};
this.getLastName = function () {
return firstAndLast.split(" ")[1];
};
this.getFullName = function() {
return firstAndLast;
};
this.setFirstName = function (first) {
firstAndLast = first + " " + firstAndLast.split(" ")[1];
};
this.setLastName = function (last) {
firstAndLast = firstAndLast.split(" ")[0] + " " + last;
};
this.setFullName = function (fullName) {
firstAndLast = fullName;
};
// Complete the method below and implement the others similarly
};
I also put the “getFullName” statement back at the bottom where it was initially, and that obviously made no change, not that I was really expecting it to. Should I reset the lesson and try pasting it back into it after it refreshes??