在添加if语句之前,我的代码工作正常。任何帮助深表感谢。

function calc() {
   var a = parseInt(document.getElementById('eersteGetal').value);
    var b = parseInt(document.getElementById('tweedeGetal').value);
    var answer = parseInt(a + b);
    var quotient = a % b;
    var bigger = '';
    if(a >= b) {
        bigger = "Number A is bigger";
    } else if(a <= b) {
        bigger = "Number B is bigger";
    } else(a === b) {
        bigger = "Number A en B are equal";
    }
    var paragraaf = document.getElementById('answer');
    paragraaf.innerHTML = answer;
    var paragraafTwo = document.getElementById('quotient');
    paragraafTwo.innerHTML = quotient;
    var paragraafThree = document.getElementById('bigger');
    paragraafThree.innerHTML = bigger;
}

最佳答案

您不能在ELSE中设置条件。

将您的IF / ELSE-STATEMENT更改为此:

if(a > b ) {
    bigger = "Number A is bigger";
}
else if(a < b) {
    bigger = "Number B is bigger";
}
else {
    bigger = "Number A en B are equal";
}

07-24 09:36