Freecodecamp: Basic JavaScript: Passing Values to Functions with Arguments

Created on 25 Sep 2020  路  10Comments  路  Source: freeCodeCamp/freeCodeCamp

Describe your problem and how to reproduce it:

The challenge instructions say:

  1. Call the function with two numbers as arguments.

But you can only pass positive integers. I suggest that either the instruction is changed to:

  1. Call the function with two positive integers as arguments.

or the regex should be changed to:

^\s*functionWithArgs\s*\(\s*[-+]?[0-9]*\.?[0-9]*.\s*,\s*[-+]?[0-9]*\.?[0-9]*.\s*\)\s*`

so that it can accept negatives and decimals.

Changing the regex would probably be simpler because it could be changed across all the language files without having to worry about translation. Plus it would probably be easier for the average reader to understand - not changing the instructions.

I can handle this once there is agreement.

Add a Link to the page with the problem:

here

Tell us about your browser and operating system:

  • Browser Name: Chrome
  • Browser Version: Version 85.0.4183.121 (Official Build) (64-bit)
  • Operating System: Macbook Catalina

If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):

Screen Shot 2020-09-24 at 9 34 38 PM
Screen Shot 2020-09-24 at 9 35 25 PM

help wanted learn

Most helpful comment

@ItsOKayCZ Sure, I believe you can try to use the assert I referenced above. Make sure to read through our Contributor docs, so that you end up creating a valid PR. Make sure to create your changes on a branch off your fork's master, to keep it from getting soiled.

All 10 comments

I definitely agree that updating the test to allow for numbers (and not just integers) is the right way to go.

I don't suppose there's an alternative to regex for the approach though? 馃

I don't suppose there's an alternative to regex for the approach though?

I was not able to think of a way. A slight modification of @kevinsmithwebdev's regex is needed for the test to pass with function declaration above it.

assert(/functionWithArgs\s*\(\s*[-+]?[0-9]*\.?[0-9]*.\s*,\s*[-+]?[0-9]*\.?[0-9]*.\s*\)\s*/.test(code.replace(/\s/g, '')));

@nhcarrigan Is there something wrong with regex? That is what it is using now, it's just that it doesn't match the description. I suppose we could parse the string manually. If the regex string is too arcane, perhaps the numbers could be captured out and tested separately. I would imagine still doing it with regex and it would be more verbose, but it might be a little more readable.

There is definitely nothing wrong with regex - it was just my understanding that the goal was to move away from using it in testing? I thought I saw some comments related to that, but I could have misread.

Sorry, I'm not familiar with that conversation. (But in all fairness, I haven't been following this end of things much, I'm just getting back into it.)

@nhcarrigan You are correct. Where possible, we want to. In this particular case, it is not possible with our existing test runner as the call to the function that they user writes just "runs" and it seems there is no way of looking at the values passed into the inside of the function.

Hello, could I work on this issue?

@ItsOKayCZ Sure, I believe you can try to use the assert I referenced above. Make sure to read through our Contributor docs, so that you end up creating a valid PR. Make sure to create your changes on a branch off your fork's master, to keep it from getting soiled.

And do it for all the languages - I assume they'd all want these changes.

And do it for all the languages - I assume they'd all want these changes.

Actually, this is not necessary. The non-English versions of the curriculum will use the testString of the English file. We will be making some change to the overall repo that will remove everything except the description, instructions, and test text of the non-English files. Since, those are the only parts needing translation as we will use the English file for the other sections.

Was this page helpful?
0 / 5 - 0 ratings