Basic Algorithm Scripting - Truncate a String

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

function truncateString(str, num) {
  let result=''
for(let i=0;i<num;i++){
  result+=str[i]
}
result+='....'
console.log(result)
  return result;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Truncate a String

Link to the challenge:

Hello! Welcome to the community :partying_face:!

Please explain the current problem you’re having :slight_smile:.

The process of explaining the problem to other people will help you understand what’s the issue with your current logic. Take a look at the Rubber Duck Debugging method.

I have made all their requirements but they still don’t pass my code

You have met none of the requirements.

For example, truncateString("A-tisket a-tasket A green and yellow basket", 8) should return the string "A-tisket..." but your function returns the following:
"A-tisket a-tasket A green and yellow basket...."