Restrict Possible Usernames: Why does adding a global flag won't work for username = 'RegexGuru'?

Your code so far


let username = "JackOfAllTrades11";
let userCheck = /^[a-z]{2,}\d*$/i; // Change this line
let result = userCheck.test(username);
let result1 = username.match(userCheck);
console.log(result1);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames

Because the global flag makes the test method behave differently
You were never taught to use the g flag with the test method because it would be rare to use it that way

If you are interested to know more check the documentation on the test() method

Using test() on a regex with the global flag

let userCheck = /^[a-z]{2,}\d*$/ig;

userCheck.test("RegexGuru");
true

userCheck.test("RegexGuru");
false

userCheck.lastIndex=0;

userCheck.test("RegexGuru");
true

Maybe the challenge that explains the test method should be expanded to include a note on the /g flag and lastIndex property