function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num && num > 3) { // a simple if statement to determine one of three outcomes…
return str.slice(0, (num - 3)) + '...'; /* If our string length is greater than the num we want to truncate at, and our truncate point is at least three characters or more into the string, we return a slice of our string starting at character 0, and ending at num - 3. We then append our '...' to the end of the string.*/
} else if (str.length > num && num <= 3) { /*if our string length is greater than the num but num is within the first three characters, we don’t have to count our dots as characters. Therefore, we return the same string as above, with one difference: The endpoint of our slice is now just num. */
return str.slice(0, num) + '...';
} else { /* Finally, if none of the above situations are true, it means our string length is less than our truncation num. Therefore, we can just return the string*/
return str;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0.
function truncateString(str, num) {
// Clear out that junk in your trunk
if (str.length > num && num > 11) {
return str.slice(0, (num - 11)) + '...';
} else if (str.length > num && num <= 11) {
return str.slice(0, num) + '...';
} else {
return str;
}
}
You are using the code from the hint, that is outdated code from when the challenge included the three dots in the length of the string, the solution would be much more simple than this
If you can understand the code in the hint you should be able to make it to solve this challenge
I was going to ask about the num-3 (: nice to know it was an old thing.
If you need more help, tell us; the best way to learn is understanding it all; and remember, pseudocode is your best friend.