vendredi 17 juillet 2020

My code should be detecting if a string has currency symbols, but it will not detect £

My code is supposed to detect currency symbols, and execute code based on the result, but the code will not detect the '£' under any circumstances. Here is the relevant code:

let requirements = [ "£", "$" ];
let mcontent = "$£50";
let y = 0;
for (let p = 0; p < requirements.length; ++p) {
    if (mcontent.includes(requirements[p])) {
        ++y;
    }
}
if (y == 1) {
    //this is considered success, only ONE currency symbol was detected. If mcontent = '$50' or '£50', we should be here.
} else {
    //this is considered failure, TWO or ZERO currency symbols were detected. In this scenario, I want the code to fail.
}

I'm aware this may not be the best way to code a function to accomplish what I'm trying to accomplish, so I'm open for better ideas/fixes for what I already have.

Aucun commentaire:

Enregistrer un commentaire