Skip to content

Problem is written poorly and is easily misleading, methinks. #7514

Closed
dunethomas opened this Issue · 2 comments

3 participants

@dunethomas

The bug isn't in the code, it's in the writing. The challenge states: "If the num is less than or equal to 3, then the length of the three dots is not added to the string length." Adding to the length of the string sounds like adding characters onto the length of a string. For greater clarity, might I suggest: "If the num is less than or equal to 3, then the additional length of the three dots is not added to the total length tested to determine the truncation point." Or something like that. Anyway, it seemed rather unclear exactly what this challenge was asking for.

Challenge Truncate a string has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function truncate(str, num) {
  // Clear out that junk in your trunk
  if (str.length <= num) return str;
  if (num > 3) { 
    str = str.substr(0,num-3) + "...";
  }
  console.log(str);
  return str;
}

truncate("A-tisket a-tasket A green and yellow basket", 11);
@sultanshaik

Also, the instructions mention that the three dots not be added if num is less than three.
But here is the expected output that ### contradicts the instruction:
truncate("A-", 1) should return "A...".
truncate("Absolutely Longer", 2) should return "Ab...".

@Spartano

the problem lies in what the code completion ask you to do. they just have to remove the "..." from the last 2 statements and add them to the previous 2, so that you can complete the chalenge.

@SaintPeter SaintPeter closed this in #7595
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.