Javascript Calculator... almost there

So I’m having problems with how stuff appears on the display, specially after having used the clearCalc method. I don’t truly understand why.

It also bothers me that on line 48, if I call that console.log function with that argument the following “if” won’t work, while if I don’t run that line, it wil. does anyone know why?

Here’s my code:

From the MDN docs:

JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y ). They store a lastIndex from the previous match. Using this internally, test() can be used to iterate over multiple matches in a string of text (with capture groups).

Try running this code on and see what happens:

const globalRx = /[\d\.]+$/g;
const notGlobal = /[\d\.]+$/;

const s = "dfj8";

console.log("Testing global regex twice...")


console.log("Testing non-global regex twice...")

Wow thanks a lot, that was the issue. I didn’t even need the flag. Solved it now!

Great find, I was reading the code yesterday and didn’t think to check the flags (I didn’t know that RegExp can be stateful : / ).

Cheers and happy coding :slight_smile:

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