why does this javascript take the "h" out of "he"?

Viewed 74

I have this javascript code and it's supposed to display 4.0026 in the alert box after the user inputs "1 he" into the prompt, but for some reason it instead decides to take only the "h" out of "he" and use that while thinking you inputted "h" only.

var first=prompt("Enter first term");
        if(first==""){
            periodictable();
        }else{
            var split=first.split(" ");
            var firsttrans=split[1].replace("h", 1.008).replace("he", 4.0026);
            alert(firsttrans);
        }

btw ignore the function invocation periodictable() because it's not related to this problem.

3 Answers
Related