Freecodecamp: What should happen when num is 0

Created on 10 May 2016  路  5Comments  路  Source: freeCodeCamp/freeCodeCamp

ISSUE/QUESTION for Repeat a string repeat a string

if num is 0 should it repeat string or string should be blank?

Description says negative numbers should be blank, but code that puts the string as blank when num is 0 also passed validation.

I think 0 should be added to validation if the string should not be blank.

first timers only help wanted

All 5 comments

@breakpoint25 Thanks for reporting this issue.

Interesting.

I am not sure if we should one more case to the test cases. But yeah there is an ambiguity in the description. I feel if the num == 0 then the function should return empty string.

Because we are not repeating the string in that case.

/cc @FreeCodeCamp/issue-moderators

I noticed this because I returned no string with 0. However, when I was looking up other user examples I found that they handled 0 specifically to make it return the string. I assumed they were correct because the description says to return no string if num is negative and 0 is not negative. So very interesting, otherwise description should be changed to return no string if num is not positive.

@raisedadead I agree with @breakpoint25 that we can just clarify the instructions to repeat for only positive numbers. So maybe change the instructions to this might help:

Repeat a given string (first argument) num times (second argument). Return an empty string if num is not a positive number.

For those wanting to fix this, here is the line of code you need to change. And you need to change it to:

"Repeat a given string (first argument) <code>num</code> times (second argument). Return an empty string if <code>num</code> is not a positive number.",

Please first read the contributing guidelines before taking care of this issue. And feel free to visit the Contributors Help if you have any questions about helping. We're there to help.

I'll take care of changing that specific line.

Will read the guidelines and follow them, and then submit a PR with this update.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MelissaManning picture MelissaManning  路  3Comments

danielonodje picture danielonodje  路  3Comments

robwelan picture robwelan  路  3Comments

ar5had picture ar5had  路  3Comments

kokushozero picture kokushozero  路  3Comments