Help, im a bit stuck in this problem, i don’t know why the for loop surpasses the max number
**Your code so far**
function truncateString(str, num) {
let text = str.split("");
let result = [];
if (str.length >= num){
for (let i = 0; i < num; i++){
result.push(text[i])
}
result = result.join("") + "...";
console.log(result);
}else{
result = str;
}
//console.log(result);
return result;
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
console.log("A-tisket a-tasket A green and yellow basket".length + 2);
console.log("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/98.0.4758.102 Safari/537.36
Challenge: Truncate a String
Link to the challenge: