So this must be a very simple explanation but I would like to understand why my second “if” statement returns “true” even though I have a string with the length of 1 and a num with a value of 1. I tried marking up my code using ` but for some reason it’s not working
Anyways, the question is why does my second if statement return true and executes the command when 1 clearly isn’t > than 1.
Thanks
function truncateString(str, num) {
if (str.length > num && num >= 3){
return str.slice(0, num - 3) + "...";
}
if (str.length > num && num <= 3){
return str.slice(0, num) + "...";
}
else {
return str.slice(0);
}
}
truncateString("A", 1);
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.