Tell us what’s happening:
After running the tests I keep getting the following errors…
truncateString("A-tisket a-tasket A green and yellow basket", 8) should return "A-tisket..."
and truncateString("Peter Piper picked a peck of pickled peppers", 11) should return "Peter Piper...".
Your code so far
function truncateString(str, num) {
// Clear out that junk in your trunk
if (num < 3){
return str.slice(0, num) + "...";
}
else {
return num >= str.length ? str : str.slice(0, num - 3) + "...";
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36.
if you want a condition as you did, say something like if there is no string length (check if its equal to zero or you can use !str.length in your first conditional. then return something to the user saying that there is no string length or just return ‘…’ or however you want to customize your string checking function. You can also add trim() inside of your logic there are many ways to customize this.
The second thing is that num is really the str.length which is the second argument passed into your truncateString() maybe the reason why you got confused is that if you take the string ‘…’ and set it to a variable then you check its length you get 3 ? thinking about these things can help you pass this challenge