不等式不显示正确的输出,JS

Inequalities not displaying right output, JS

我正在尝试制作一个简单的期末成绩计算器,但在不等式的输出方面遇到了一些问题。它由 4 个等级组成,每个等级都有一个双倍值。然后将他们乘以他们尊重的权重并放入一系列不等式中以查看参与者将获得哪个等级。不幸的是,即使双精度值正确,我得到的字母值也不正确。我认为这是我的不平等,但我无法弄清楚他们有什么问题。非常感谢任何帮助!

我不想包含所有代码,因为它太多了,但它们都对应于它们各自的下拉菜单,就像这个一样。

<form name="GPA">
            <select name="demoSelect" onchange="showData2()">
        <option value="zilch">Select Quarter 1:</option>
        <option id="4.0" >A</option>
        <option id="3.5" >B+</option>
        <option id="3.0" >B</option>
        <option id="2.5" >C+</option>
        <option id="2.0" >C</option>
        <option id="1.5" >D</option>
        <option id="0.0" >F</option>
    </select>
        </form>

表格结束

function showData() {
        var theSelect = GPA.demoSelect;
        var firstGrade = document.getElementById('firstGrade');
        firstGrade.innerHTML = (theSelect[theSelect.selectedIndex].id);
        var grade = theSelect[theSelect.selectedIndex].id;
        var finalGrade = parseFloat(grade);

        var theSelect = GPA2.demoSelect2;
        var secondGrade = document.getElementById('secondGrade');
        secondGrade.innerHTML = (theSelect[theSelect.selectedIndex].id);
        var grade2 = theSelect[theSelect.selectedIndex].id;
        var finalGrade2 = parseFloat(grade2);

        var theSelect = GPA3.demoSelect3;
        var secondGrade = document.getElementById('thirdGrade');
        thirdGrade.innerHTML = (theSelect[theSelect.selectedIndex].id);
        var grade3 = theSelect[theSelect.selectedIndex].id;
        var finalGrade3 = parseFloat(grade3);

        var theSelect = GPA4.demoSelect4;
        var forthGrade = document.getElementById('forthGrade');
        forthGrade.innerHTML = (theSelect[theSelect.selectedIndex].id);
        var grade4 = theSelect[theSelect.selectedIndex].id;
        var finalGrade4 = parseFloat(grade4);


        var FinalCalc = ((finalGrade * 0.2) + (finalGrade2 * 0.3) + (finalGrade3 * 0.2) + (finalGrade4 * 0.3));

        if (FinalCalc >= 3.75) {
            document.getElementById("output2").innerHTML = "A";
        } else if (FinalCalc >= 3.25 && FinalCalc < 3.75) {
            document.getElementById("output2").innerHTML = "B+";

        } else if (FinalCalc >= 2.75 && FinalCalc < 3.25) {
            document.getElementById("output2").innerHTML = "B";

        } else if (FinalCalc >= 2.25 && FinalCalc < 2.75) {
            document.getElementById("output2").innerHTML = "C+";

        } else if (FinalCalc >= 1.75 && FinalCalc < 2.25) {
            document.getElementById("output2").innerHTML = "C";

        } else if (FinalCalc >= 1.25 && FinalCalc < 1.75) {
            document.getElementById("output2").innerHTML = "D";

        } else if (FinalCalc < 1.25) {
            document.getElementById("output2").innerHTML = "F";

        }
        document.getElementById("output").innerHTML = FinalCalc;

    }

您提供的部分工作正常:

function showData() {
        var theSelect = GPA.demoSelect;
        var firstGrade = document.getElementById('firstGrade');
        firstGrade.innerHTML = (theSelect[theSelect.selectedIndex].id);
        var grade = theSelect[theSelect.selectedIndex].id;
        var finalGrade = parseFloat(grade);

        var FinalCalc = finalGrade * 0.2
        //var FinalCalc = ((finalGrade * 0.2) + (finalGrade2 * 0.3) + (finalGrade3 * 0.2) + (finalGrade4 * 0.3));


        if (FinalCalc >= 3.75) {
            document.getElementById("output2").innerHTML = "A";
        } else if (FinalCalc >= 3.25 && FinalCalc < 3.75) {
            document.getElementById("output2").innerHTML = "B+";

        } else if (FinalCalc >= 2.75 && FinalCalc < 3.25) {
            document.getElementById("output2").innerHTML = "B";

        } else if (FinalCalc >= 2.25 && FinalCalc < 2.75) {
            document.getElementById("output2").innerHTML = "C+";

        } else if (FinalCalc >= 1.75 && FinalCalc < 2.25) {
            document.getElementById("output2").innerHTML = "C";

        } else if (FinalCalc >= 1.25 && FinalCalc < 1.75) {
            document.getElementById("output2").innerHTML = "D";

        } else if (FinalCalc < 1.25) {
            document.getElementById("output2").innerHTML = "F";

        }
        document.getElementById("output").innerHTML = FinalCalc;

    }

在这里查看:http://jsfiddle.net/wjvkg8q9/15/

注意你的函数叫showData(),onchange事件调用showData2() 您是否可能在其余代码中编辑了错误的重复函数?

P.S:我已经在 fiddle 中评论了其他等级变量,但正如您所说,它们是对应的。