Learn Advanced Array Methods by Building a Statistics Calculator - Step 3

Tell us what’s happening:

Can somebody please tell me, what is it I’m doing wrong?
How do I use the regex properly in this situation?

THE QUESTION:

"Now that you have the value of the input, you need to split it into an array of numbers. Use the .split() method to do this.

The .split() method takes a string and splits it into an array of strings. You can pass it a string of characters or a RegEx to use as a separator. For example, string.split(",") would split the string at each comma and return an array of strings.

Use the /,\s*/g regex to split the value string by commas. You can tweak it based on the number of spaces separating your values. Store the array in an array variable."

/* file: script.js */

// User Editable Region

const calculate = () => {
  const value = document.querySelector("#numbers").value;
  const regex = /,\s*/g;
  const array = value.split(match(regex));
  }

// User Editable Region

Your browser information:

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

Challenge Information:

Learn Advanced Array Methods by Building a Statistics Calculator - Step 3

use the regex as argument of split directly, do not use match

I actually solved it yesterday right after I posted this question. Anyway, one thing that really drives me up a wall on some of these exercises is how poorly explained or poorly formulated they are.

1 Like

if you have feedback for specific steps, feel free to open an issue about that so that they can be improved

it seems the exercises are made for seniors to seniors . novices like me suffer a lot.
chat gpt is really hellpfull sometimes

I don’t think this step is poorly explained at all.

The .split() method takes a string and splits it into an array of strings. You can pass it a string of characters or a RegEx to use as a separator.

Use the /,\s*/g regex to split the value string by commas.

It seems pretty clear what is asked for. I would suggest slowing down and reading it more carefully.


I can assure you they are not.

I’m sure there are plenty of steps that can, and will, have their instructions improve. But this is not one of them, in my opinion.