dimanche 22 novembre 2020

JavaScript if/else Statement Input Data

Please help me, I am studying on my own and need help, I want to create an "JavaScript else if statement" but this doesn't work.

Who wants to make input

// If "x" is greater than or equal to 1 and "x" is less than 10, and "y" is equal to 100, output "+"

// If "x" is greater than or equal to 11 and "x" is less than 100, and "y" is equal to 100, output "++"

// If "x" is greater than or equal to 1 and "x" is less than 10, and "y" is equal to 1, output "+++"

// If "x" is greater than or equal to 10, and "y" is equal to 1, output "++++"

The code that I tried to make, below

<!DOCTYPE html>
<html>
<body>

<p>Please Help:</p>

<input id="numb1" type="text">
<input id="numb2" type="text">
<button type="button" onclick="myFunction()">Submit</button>

<p id="tes"></p>

<script>
function myFunction() {
  var x, y, text;

  x = document.getElementById("numb1").value;
  y = document.getElementById("numb2").value;
   
  if (x > 1 || x < 10 || y == 100) {
    text = "+";
  } else if (x > 11 || x < 100 || y == 100) {
    text = "++";
  } else if (x > 1 || x < 10 || y == 1) {
    text = "+++";
  } else if (x > 10 || y == 1) {
    text = "++++";
  }
  document.getElementById("tes").innerHTML = text;
}
</script>

</body>
</html>

Aucun commentaire:

Enregistrer un commentaire