Hi,
I attempted to match the ending for the first case (bastian,n) but somehow it doesn’t seem to return to true.
I also realised that I am supposed to use a substring method, but I am still curious as to why it wouldn’t return to true in my code (at least for the first case).
function confirmEnding(str, target) {
// split str into elements array --> newStr
let newStr = str.split("");
//console.log(newStr);
// split target into elements array --> newTarget
let newTarget = target.split("");
//console.log(newTarget);
// -- slice returns the portion cut out as a new array;
let lengthToSlice = newStr.length - newTarget.length; //index of where to start slicing, including the point of starting
console.log(lengthToSlice);
let stringToCheck = newStr.slice(lengthToSlice);
//check if newStr array == newTarget array
console.log(stringToCheck);
console.log(newTarget);
if (stringToCheck == newTarget){
return true;
} else {
return false;
}
}
confirmEnding("Bastian", "n");
Thanks!