+ 4
[Javascript] If-else if-else Question [CLOSED]
Can you please check this code? Although, I've found a solution, I must return 2 times str, but this doesn't seem to work with all the test cases: if (str.length === num || temp1 >str) { return str; } It fails, at least, with truncateString("A-", 1); and I can't figure out why. I'm guessing the issue is how I built the conditions... but I'm stuck. https://code.sololearn.com/WnBvZ78oXeBh/#js
11 Réponses
+ 5
You're welcome, good luck and keep going!!
+ 3
Fixed https://code.sololearn.com/WiTjH9FdKXcv/?ref=app
I misunderstood sorry
+ 3
What are the outputs you expect?
+ 3
I don't understand, why should ("A-",1) return "A..."? The function you want is not natural at all :/
Anyway, with my given solution you might be able to simple change the num's value if the string length is lower of equal to 3
+ 2
Hope that helps
+ 2
Thank you, カンタンジャヌエル, but that code doesn't pass truncateString("A-", 1); and others test cases.
+ 2
OH wait a second
+ 2
ok. Thank you.
+ 1
Seems to be better. But that one won't make pass these test cases (at least):
truncateString("A-tisket a-tasket A green and yellow basket", 11)
truncateString("Peter Piper picked a peck of pickled peppers", 14)
+ 1
All instructions and expected outputs are in the code, commented.