I am struggling with " Basic Algorithm Scripting: Truncate a String". I recieve proper results, but
I can’t pass the challenge. Am I missing something?
function truncateString(str, num) {
let arr=str.substring(0,num);
arr+="...";
return arr;
}
truncateString("A-tisket a-tasket A green and yellow basket", 2);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.
also, don’t return a console.log
if you write return console.log() then the output of your function is undefined
you can put the function call in a console.log if you want console.log(truncateString("Hello", 25))
Yeah, I’m aware of that. In original post I didn’t included console.log(), I did it in reply to you to show what is a result of arguments (“Hello”, 25). My original code doesn’t include console.log(), as you can see at the beginning of thread
Challenge tells me to return the truncated string with a ... ending, even if i change code like this I can’t pass the challenge:
function truncateString(str, num) {
str=str.substring(0,num);
str+="...";
return str;
}
console.log(truncateString("A-tisket a-tasket A green and yellow basket", 4));
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
also note this test case:
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) should return "A-tisket a-tasket A green and yellow basket".