Truncate a string test seem to have bugs

Tell us what’s happening:
Two of the tests fail, is this a bug or do I really need to debug my code?

Your code so far

function truncateString(str, num) {

return str.length > num ? str.slice(0,num) + '...' : string;

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.15; rv:82.0) Gecko/20100101 Firefox/82.0.

Challenge: Truncate a String

Link to the challenge:

1 Like

The string in the last word is a keyword. Use str instead

Change this.

return str.length > num ? str.slice(0,num) + '...' : string;

To this

return str.length > num ? str.slice(0,num) + '...' : str;

you really need to debug yout code

check what the failint tests return


It is great that you solved the challenge, but instead of posting your working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

1 Like

Sure. Will do this next time. :+1:

Thanks for the feedback, all your answers make me realize I need to review things much more carefully. Thank you.