Truncate-a-string (beta version)

Tell us what’s happening: The only tests I cant pass are the ones with the .length and no real num as the second argument. I am lost on how to implement this into my solution.

Also, the directions on the beta for this exercise seem to be different from the normal in terms of not having to count the “…” as part of the length. Is this correct?

Your code so far


function truncateString(str, num) {
  let newStr = str.slice(0, num);
  newStr = newStr + "...";
  console.log(newStr);
  return newStr;
}

truncateString("A-tisket a-tasket A green and yellow basket", 8);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:

The second argument in the ones with .length is still a number (integer), so that is not the issue.

The beta instructions are slightly different in regards to how you are suppose to use the “…”. That is why your are failing the following test:

truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)

Your function should return:

‘A-tisket a-tasket A green and yellow basket.’

but instead returns:

‘A-tisket a-tasket A green and yellow basket…’

Your current solution always puts “…” on the end no matter what. You only want to add the “…” ending if str’s length is greater than num. In the above test, the length of str is 43 and num is 43, so you would not add the “…” to the end of str.

Thanks so much for your help as always! For some reason I was just dead set on the problem being the .length part