Hi everyone! Here’s my solution to the challenge that, to my surprise, passed:
function truncateString(str, num) {
// Clear out that junk in your trunk
let newStr = ''
if(str.length > num) {
newStr = str.slice(0, num) + "...";
console.log(newStr);
} else {return newStr = str;}
return newStr;
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
The reason I’m surprised is because I was looking at the solution, trying to understand it while writing my own code, and the solution has 3 outcomes in the if else
statement. But I made mine simple. I think it’s too simple I can’t believe it passed. I still don’t understand the solution code completely and I feel bad for going through if I’m missing something important.
Here’s the FCC Challenge Solution link for your reference.