Tell us what’s happening:
The problem is that even when you write the right solution the test aren’t getting passed. The following code solves the challenge, but 2/5 of the tests fail.
Apologies for my grammar and spelling.
Your code so far
let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/g;
let result = myRegex.test(myString);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0.
Can you run this /(Eleanor|Franklin).*Roosevelt/g.test('Franklin D. Roosevelt') code in your browser console. It will return true. why the problem is not causing.
because when the test method returns false then the check start again at the beginning of the string.
try without g flag, everything will return true
If the regex has the global flag set, test() will advance the lastIndex of the regex. A subsequent use of test() will start the search at the substring of str specified by lastIndex (exec()will also advance the lastIndex property). It is worth noting that the lastIndex will not reset when testing a different string.