vendredi 10 juillet 2020

Why is this if else not returning anything? I am a beginner in Javascript

My function works except for the part where the if else statement checks if the values are 0...

const button = document.querySelector("#deKnop");
button.addEventListener("click", deling);

function deling() {
  const getal1 = parseFloat(document.querySelector("#getal1").value);
  const getal2 = parseFloat(document.querySelector("#getal2").value);
  const output = document.querySelector(".vb"); {

  }

  if (getal1 === 0) {
    output.innerHTML = getal1 / getal2;
  }
  else if (getal1 === 0 && getal2 === 0) {
    console.log('niet nul zijn');
    alert("Je kan niet delen door 0!");
  }

  else if (getal2 === 0) {
    output.innerHTML = getal2 / getal1
  }

  else if (getal1 > getal2) {
    // console.log('getal 1 groter');
    output.innerHTML = getal1 / getal2;

  }

  else if (getal1 < getal2) {
    // console.log("getal 2 groter")
    output.innerHTML = getal2 / getal1

  }

  else if (getal1 === getal2) {
    output.innerHTML = getal1 / getal2

  }


}

Aucun commentaire:

Enregistrer un commentaire