Truncate a String 1

<%= @topic_view.topic.title %>
<%= @topic_view.topic.average_rating %> <%= @topic_view.topic.posts.count { |p| !!p.custom_fields['rating'] } %>

Please help

Your code so far

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (str.length > num && num > 3) {
    return str.slice(0, (num - 3)) + '...';
  } else if (str.length > num && num <= 3) {
    return str.slice(0, num) + '...';
  } else {
    return str;
truncateString("A-tisket a-tasket A green and yellow basket", 8);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:

What do you need help with? It is a good idea to tell people what you are having trouble with and explain why you did what you did. “Please help” does not do that.

You have not followed the instructions and made it too complicated. Why have you set conditions against the number 3? There are no instructions to do so. The ‘…’ gets concatenated at the end of the substring.

You can complete this with only ONE ‘if’ block, no else blocks: what should happen if str is longer than num?