[Javascript] If-else if-else Question [CLOSED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

3rd Sep 2017, 5:00 PM
Kustaa
11 Answers
+ 5
You're welcome, good luck and keep going!!
3rd Sep 2017, 5:52 PM
Dapper Mink
Dapper Mink - avatar
3rd Sep 2017, 5:08 PM
Dapper Mink
Dapper Mink - avatar
3rd Sep 2017, 5:18 PM
Dapper Mink
Dapper Mink - avatar
+ 3
What are the outputs you expect?
3rd Sep 2017, 5:26 PM
Dapper Mink
Dapper Mink - avatar
+ 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
3rd Sep 2017, 5:41 PM
Dapper Mink
Dapper Mink - avatar
+ 2
Hope that helps
3rd Sep 2017, 5:11 PM
Dapper Mink
Dapper Mink - avatar
+ 2
Thank you, カンタンジャヌエル, but that code doesn't pass truncateString("A-", 1); and others test cases.
3rd Sep 2017, 5:15 PM
Kustaa
+ 2
OH wait a second
3rd Sep 2017, 5:16 PM
Dapper Mink
Dapper Mink - avatar
+ 2
ok. Thank you.
3rd Sep 2017, 5:44 PM
Kustaa
+ 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)
3rd Sep 2017, 5:26 PM
Kustaa
+ 1
All instructions and expected outputs are in the code, commented.
3rd Sep 2017, 5:33 PM
Kustaa