Questions about: Basic Algorithm Scripting: Truncate a String

Question 1: Why is my second solution not working?

//console.log(str.slice(0,num)+"...";) // works
//return str.slice(0,num)+"..."; // works
console.log("".concat(str.slice(0,num),"...")); // doesn't work
return "".concat(str.slice(0,num),"..."); // doesn't work

Question 2: Easy way not always best way
I use a lot of methods in my solutions. And that makes me feel a bit like I’m cheating. Shouldn’t my solution look like the “advanced solution” anymore? Maybe I’ll learn a lot more if I use fewer methods, because now I’m not building a fundamental basis?

This is de advanced solution:

function truncateString(str, num) {
  if (str.length <= num) {
    return str;
  } else {
    return str.slice(0, num > 3 ? num - 3 : num) + '...';
  }
}

The solutions in the guide refer to an old version of the challenge so you shouldn’t use them as reference for the solution

For concat not working… I will experiment with it a bit

Remember that you are missing the case for when you don’t need to truncate the string

Remember that you are missing the case for when you don’t need to truncate the string

Really good point

The solutions in the guide refer to an old version of the challenge so you shouldn’t use them as reference for the solution

Okay good to know.

For concat not working… I will experiment with it a bit

Okay let me know. :slight_smile:

hi there…

The slice function is the array manipulation function and the substring string manipulation function
Why does everyone use the slice function?
I used substring, concat
I have solved the problem, is not this the intended solution?

Thank you for your kindness.

I need to check the MDN document. :blush: