Passing Basic Algorithm Scripting: Truncate a String

I passed the test with this code except for when it ran:

1). truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) should return “A-tisket a-tasket A green and yellow basket”.

2). truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2) should return “A-tisket a-tasket A green and yellow basket”.

Any advice for alterations that need to be done to fully complete the challenge?

Your code so far


function truncateString(str, num) {
if (num >= str.lenght) {
  return str ;
} else {
  str = str.substring(0,num);
  return str+ "...";
}
}

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_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Truncate a String

Link to the challenge:

Just a quick look, I can see that you misspelled “length”.

That was my issue, English is not my native language. So, silly spelling errors go over my head!
thnks

1 Like

That’s cool. Unfortunately, English spelling makes little sense. When you get to working locally on projects, I’ve found that packages like Code Spell Checker in VSC are very helpful - even as a native English speaker it sometimes catches little things for me.

1 Like