let exampleStr = "The sun is out today.";
let unRegex = /.un/g; // Change this line
let result = unRegex.test(exampleStr);
console.log(exampleStr.match(unRegex));
console.log(result);
exampleStr = "Seven days without a pun makes one weak.";
console.log(exampleStr.match(unRegex));
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:67.0) Gecko/20100101 Firefox/67.0.
The above string examples will not pass the challenge test, yet they do log properly to the console. Befuddled.
Yes. The code that I had written for this challenge, when tested with :
let exampleStr = "The sun is out today.";
exampleStr = "Seven days without a pun makes one weak.";
console.log(exampleStr.match(unRegex));
console.log(result);
The log reads in the console:
sun //as a string
true //as a boolean
pun //as a string
true //as a boolean
yet the challenge tests for those sentences does not clear.
I’m curious as to why.
If the regex has the global flag set, test() will advance the lastIndexof 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.