I understand after reading ask for a hint that this might not be the most efficient way to write this code but I was trying to go as far as i could without looking. does anyone know if can be solved this type of way/where I’m going wrong?
Your code so far
function truncateString(str, num) {
var splitstr = str.split('')
var newstring = ''
for(var i = 0; i < num; i++)
if (str.length > num){
newstring = splitstr[i].concat;
}
if (str.length < num) { return str
}
return newstring + '...'
}
console.log(newstring)
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_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.
now I don’t think ti passes anymore. what about when num is higher than the string length? as it is it just returns ...
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.