Answers to Using the test() method

It was easy to solve, on my Visual Studio anyway, but the problem is freeCodeCamp’s compiler would not accept anything other that the result shown in the Help Solution.
My code had 2 different answers and both worked in Visual Studio. Am I missing something? This doesn’t make sense to me.

Your code so far

let myString = "Hello, World!";
let myRegex = /Hello/;
// My first answer:
// My second answer:
let answer = myRegex.test(myString);
// Both were rejected. The only answer acceptable was:
let result = myRegex.test(myString);

let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex; // Change this line

Your browser information:

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

Challenge: Using the Test Method

Link to the challenge:

Yes, if you change the name of the variable then I would expect the test to fail. If you change the name of the result variable, then the tests have no clue where you put the answer.


Thank you for that. I revisited the assignment and realized they already pre-setup the code using the variable ‘result’ and by changing that the test wouldn’t pass. I just get frustrated sometimes when I have to check the answer for a simple assignment that I should be able to figure out on my own. Thanks again I will pay more attention to these details.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.