Lilla
Lilla

Reputation: 209

Switch giving wrong values in JavaScript

Running the following code in Google Chrome I have the switch statement going to default when comparing minus. Why am I encountering this issue? How can I solve it? Thank you all in advance!

var code="F+F−F−F+F"
for(var i = 0; i < code.length; i++) {      
    alert(code[i]);
    switch(code[i]) {
        case 'F':
            alert("F");
            break;

        case 'G':
            alert("G");
            break;
        case '+':
            alert("+");
            break;

        case '-':
            alert("-");
            break;

        default:
            alert("default");
            break;
    }
}

Upvotes: 0

Views: 66

Answers (1)

madox2
madox2

Reputation: 51881

The problem is that does not equals -

Upvotes: 3

Related Questions