Skip to content
Advertisement

Calculation not being performe properly in JavaScript

I have the following code that is converting characters entered in an input field into other characters (namely, entering an e or and E and converting it to a 3, likewise for a t or T into a 7).
I am also calculating the percentage of the characters that were converted, but my calculation is not being performed properly and was wondering if someone can help with this.
For example, if someone enters in a string like 373, it will not convert the characters (as expected), but the number of converted characters will be 3 when they should be 0 instead.

JavaScript

Advertisement

Answer

You can pass a function when replacing characters that would also count

JavaScript

Now totalRepalcements will hold the total number of replacements that have been done.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement