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
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.
And I can assure you, as a junior, that this is poorly explained. You should see my browser history thats full of chatgpt, this forum and if all else fails, the next question to pass the question. The questions sometimes are so badly explained that you cant even understand whats going on so you cant search it! I’m not even getting into some questions not going through even though its correct.
if you have issues with a specific step, please open a topic on the forum, and once you pass it, you can open an issue on github with suggestions on how to improve the step
The only improvement I would make is the wording of what it is called on to clarify the “takes” part. Takes usually refers to parameters and not the data type the method is called on. I guess adding a more complete code example is an option as well.
The .split() method is called on a string and splits it into an array of strings. You can pass it an argument to use as a separator, the argument can be a string or a RegEx.
const words = "Camper-Cat".split("-");
console.log(words); // ["Camper", "Cat"]
Use the /,\s*/g regex to split the value string by commas.
Something being poorly explained can make it hard to understand, but inferring that something that is hard to understand must be poorly explained is just circular reasoning.