This isn’t really a thread asking for help so much as it is a minor criticism for this exercise. It seems misleading to me the result they expect relative to the explanation given. Below is my code that should work, but doesn’t:
let myString = "Hello, World!";
let myRegex = /Hello/;
myRegex.test(myString);
Here is the example given in the exercise;
let testStr = "freeCodeCamp";
let testRegex = /Code/;
testRegex.test(testStr);
Instruction: " Apply the regex myRegex
on the string myString
using the .test()
method."
This is exactly what I’ve done. Below that, it says in steps:
-You should use .test()
to test the regex.
-Your result should return true
.
The latter condition remains false because I have not created an arbitrary “result” variable that I can see they have included in their solution. This is not required for the code to work nor does it logically follow from the instructions given, IMO, especially as the example they give directly misleads one to think it should be done the way I did it.
Maybe one could call it nitpicking, but it genuinely confused me for a minute. “Your result should return true” does not mean to me, “You should make a result variable and assign the regex test to it.”
I would recommend changing the text to either include
"let result = testRegex.test(testStr); " in the example code, or specify that you actually want a result var in the steps.
Challenge: Using the Test Method
Link to the challenge: