Truncate a String (str to array) no output

Tell us what’s happening:
What is wrong in my code i just converted string into array then return it by using array index.

Your code so far

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var arr=str.split('');
  return  arr[num-1]+"...";

truncateString("A-tisket a-tasket A green and yellow basket", 8);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:

You are returning the num-th character in the string and three dots
What happens if the string has less characters than that?

Is this what the challenge is asking?

1 Like

oh! I am completely out. thanks

I suggest you wrap the last line of your code (the function call) in this: console.log(JSON.stringify(...)), so you know what your code is returning

Plus use it to check the value of any variable that you want to check about

1 Like