根据学时计算费用

时间:2019-07-10 20:44:59

标签: javascript

我是JavaScript的新手,我正在尝试根据班级类型,居住时间和学时确定学费和费用的成本估算器。我有学费,但不知道如何计算费用。 fees.png

如果其他方法不起作用,请尝试我能想到的一切。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
      function formHandler(form) {
        var tuition1 = eval(form.tuition1.value);
        var tuition2 = eval(form.tuition2.value);
        var tuition3 = eval(form.tuition3.value);
        var hours1 = eval(form.hours1.value);
        var hours2 = eval(form.hours2.value);
        var hours3 = eval(form.hours3.value);
        var t1 = tuition1 * hours1;
        var t2 = tuition2 * hours2;
        var t3 = tuition3 * hours3;
        var oncfee1 = 0;
        var olcfee1 = 0;
        var cjusfee1 = 0;
        //Calculate on campus fees
        if (hours1 === "1") {
          oncfee1 = 95.25;
        } else if (hours1 === "2") {
          oncfee1 = 123.5;
        } else if (hours1 === "3") {
          oncfee1 = 151.75;
        } else if (hours1 === "4") {
          oncfee1 = 237.5;
        } else if (hours1 === "5") {
          oncfee1 = 265.75;
        } else if (hours1 === "6") {
          oncfee1 = 294.0;
        } else if (hours1 === "7") {
          oncfee1 = 549.25;
        } else if (hours1 === "8") {
          oncfee1 = 577.5;
        } else if (hours1 === "9") {
          oncfee1 = 605.75;
        } else if (hours1 === "10") {
          oncfee1 = 634.0;
        } else if (hours1 === "11") {
          oncfee1 = 662.25;
        } else if (hours1 === "12") {
          oncfee1 = 690.5;
        } else if (hours1 === "13") {
          oncfee1 = 718.75;
        } else if (hours1 === "14") {
          oncfee1 = 747.0;
        } else if (hours1 === "15") {
          oncfee1 = 775.25;
        } else if (hours1 === "16") {
          oncfee1 = 792.5;
        } else if (hours1 === "17") {
          oncfee1 = 809.75;
        } else if (hours1 === "18") {
          oncfee1 = 827.0;
        } else if (hours1 === "19") {
          oncfee1 = 844.25;
        } else if (hours1 === "20") {
          oncfee1 = 861.5;
        } else if (hours1 === "21") {
          oncfee1 = 878.75;
        } else {
          oncfee1 = 0;
        }
        //Calculate online fees
        if (hours2 === "1") {
          olcfee1 = 61.25;
        } else if (hours2 === "2") {
          olcfee1 = 118.5;
        } else if (hours2 === "3") {
          olcfee1 = 175.75;
        } else if (hours2 === "4") {
          olcfee1 = 233.0;
        } else if (hours2 === "5") {
          olcfee1 = 290.25;
        } else if (hours2 === "6") {
          olcfee1 = 347.5;
        } else if (hours2 === "7") {
          olcfee1 = 404.75;
        } else if (hours2 === "8") {
          olcfee1 = 462.0;
        } else if (hours2 === "9") {
          olcfee1 = 519.25;
        } else if (hours2 === "10") {
          olcfee1 = 576.5;
        } else if (hours2 === "11") {
          olcfee1 = 633.75;
        } else if (hours2 === "12") {
          olcfee1 = 691.0;
        } else if (hours2 === "13") {
          olcfee1 = 748.25;
        } else if (hours2 === "14") {
          olcfee1 = 805.5;
        } else if (hours2 === "15") {
          olcfee1 = 862.75;
        } else {
          olcfee1 = 0;
        }
        //Calculate CJUS online fees
        if (hours3 === "1") {
          cjusfee1 = 61.25;
        } else if (hours3 === "2") {
          cjusfee1 = 118.5;
        } else if (hours3 === "3") {
          cjusfee1 = 175.75;
        } else if (hours3 === "4") {
          cjusfee1 = 233.0;
        } else if (hours3 === "5") {
          cjusfee1 = 290.25;
        } else if (hours3 === "6") {
          cjusfee1 = 347.5;
        } else if (hours3 === "7") {
          cjusfee1 = 404.75;
        } else if (hours3 === "8") {
          cjusfee1 = 462.0;
        } else if (hours3 === "9") {
          cjusfee1 = 519.25;
        } else if (hours3 === "10") {
          cjusfee1 = 576.5;
        } else if (hours3 === "11") {
          cjusfee1 = 633.75;
        } else if (hours3 === "12") {
          cjusfee1 = 691.0;
        } else if (hours3 === "13") {
          cjusfee1 = 748.25;
        } else if (hours3 === "14") {
          cjusfee1 = 805.5;
        } else if (hours3 === "15") {
          cjusfee1 = 862.75;
        } else {
          cjusfee1 = 0;
        }
        var fees = oncfee1 + olcfee1 + cjusfee1;
        var cost = t1 + t2 + t3 + fees;
        form.t1.value = "$" + t1;
        form.t2.value = "$" + t2;
        form.t3.value = "$" + t3;
        form.fees.value = "$" + fees;
        form.costresult.value = "$" + cost;
      }
    </script>
  </head>
  <body>
    <form method="post" name="testform">
      <div>
        <table
          id="AutoNumber1"
          summary="calculate the cost per semester for 
    undergraduate students"
        >
          <tbody>
            <tr>
              <td colspan="2">
                <label for="tuition1">On campus class tuition </label>
                <select id="tuition1" name="tuition1">
                  <option selected="selected" value="0">None</option>
                  <option value="203">Resident</option>
                  <option value="443">Non Resident</option>
                </select>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <label for="hours1"
                  >Enter number of On campus credit hours
                </label>
                <input
                  id="hours1"
                  name="hours1"
                  size="5"
                  type="text"
                  value="0"
                />
              </td>
            </tr>
            <br />
            <tr>
              <td colspan="2">
                <label for="tuition2">Online or Blended class</label
                >&nbsp;<select id="tuition2" name="tuition2">
                  <option selected="selected" value="0">None</option>
                  <option value="261">Online/Blended class Resident</option>
                  <option value="396">Online/Blended class Non Resident</option>
                </select>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <label for="hours2"
                  >Enter number of Online or Blended credit hours
                </label>
                <input
                  id="hours2"
                  name="hours2"
                  size="5"
                  type="text"
                  value="0"
                />
              </td>
            </tr>
            <br />
            <tr>
              <td colspan="2">
                <label for="tuition3"
                  >Online or Blended Criminal Justice class</label
                >&nbsp;<select id="tuition3" name="tuition3">
                  <option selected="selected" value="0">None</option>
                  <option value="280"
                    >Online/Blended Criminal Justice class Resident</option
                  >
                  <option value="405"
                    >Online/Blended Criminal Justice class Non Resident</option
                  >
                </select>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <label for="hours3"
                  >Enter number of Online or Blended Criminal Justice credit
                  hours</label
                >
                <input
                  id="hours3"
                  name="hours3"
                  size="5"
                  type="text"
                  value="0"
                />
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <p>
                  <button
                    name="CostResult"
                    onclick="javascript:formHandler(this.form)"
                    type="button"
                  >
                    Calculate Estimated Semester Cost
                  </button>
                </p>
              </td>
            </tr>
            <tr>
              <td><label for="t1">Tuition On Campus Class</label></td>
              <td><input id="t1" name="t1" size="10" type="text" /></td>
            </tr>
            <tr>
              <td><label for="t2">Tuition Online / Blended Class</label></td>
              <td><input id="t2" name="t2" size="10" type="text" /></td>
            </tr>
            <tr>
              <td>
                <label for="t3">Tuition Online / Blended CJUS Class</label>
              </td>
              <td><input id="t3" name="t3" size="10" type="text" /></td>
            </tr>
            <tr>
              <td><label for="fees">Fees</label></td>
              <td><input id="fees" name="fees" size="10" type="text" /></td>
            </tr>
            <tr>
              <td>
                <label for="costresult">Total Estimated Semester Cost</label>
              </td>
              <td>
                <input
                  id="costresult"
                  name="costresult"
                  size="10"
                  type="text"
                />
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </form>
  </body>
</html>

费用根据学时和班级类型而定。目前,我无法返回结果。我想退回全部费用。

1 个答案:

答案 0 :(得分:0)

如果由于使用“ ===”而需要使用“ ==”,则不能输入else。

如果您想了解更多信息,请检查一下。 Link