Javascript提示窗口无法使用if语句打开

时间:2015-09-12 00:21:19

标签: javascript

我正在尝试创建一个简单的Javascript应用程序,它通过提示窗口从用户那里获取输入。当我只有单个“if”语句时,提示窗口打开正常。但是,当我之后有“else-if”语句时,窗口不再弹出。这里有什么我想念的吗?这是一段代码:

    var gender = prompt("Is the person male or female? (enter M or F)");
    var male = "M";
    var female = "F";
    var a, b, c, d, e, f;

    if(gender.localeCompare(male) == 0)
    {
         a = -216.0475144;
         b = 16.2606339;
         c = -0.002388645;
         d = -0.00113732;
         e = 7.01863 * (Math.pow(10,-6));
         f = -1.291 * (Math.pow(10,-8));
    }
    else if (gender.localeCompare(female) == 0) //If this portion is commented out, then it works fine
    {
         a = 594.31747775582;
         b = -27.23842536447;
         c = 0.82112226871;
         d = -0.00930733913;
         e = 0.00004731582;
         f = =0.00000009054;
    }
    else
    {
        document.write("Please try again!");
    }

2 个答案:

答案 0 :(得分:0)

错误位于第二个块的最后一行

f = =0.00000009054;

将其更改为

f = 0.00000009054;

答案 1 :(得分:0)

f = =0.00000009054;语法错误是最容易发现的错误。下次请自己找。使用浏览器的控制台!在声明中,一个= - 字符太多了。