Vikitha Prem
Vikitha Prem

Reputation: 13

if Function is returning the same output

When the user selects an answer, the code below is supposed to give different results; however, it just gives the same result. Why is it giving the same result when the button is pressed?

1.Is the network problem affecting just your pc? <BR>

<select id="Area">

  <option value="Yes">Yes</option>

  <option value="No">No</option>

  </select>

<br>

<br><p>



2.Can you access the internet? <BR> 



 <select id="Internet">

  <option value="Yes">Yes</option>

  <option value="No">No</option>

  <option value="Yes,but is slow">Yes,but is slow</option>

  <option value="Drop in connection">Drop in connection</option>

</select>

<br>

<br><p>



3.Are you receiving any error message saying remote system could not be found or connection has timed out?<BR>

<select id="Errors">

  <option value="Remote">Remote system could not be found</option>

  <option value="Connection">Connection has timed out</option>

  <option value="No">No error messages </option>

  </select>

<br>

<br><p>



4.Have you changed any software or Hardware before the problem occurred?<BR> 



 <select id="Change">

  <option value="Software">Software</option>

  <option value="Hardware">Hardware</option>

  <option value="Both">Both</option>

  <option value="None">None </option>

</select>

<br>

<br><p>





<button onclick="myFunction()">Detect</button>



<p id="Solution"></p>



<script>

function myFunction()

{

    var AreaElem =  document.getElementById("Area");

    var Area = AreaElem.options[AreaElem.selectedIndex].value;

    var InternetElem =  document.getElementById("Internet");

    var Internet= InternetElem.options[InternetElem.selectedIndex].value;
    var ErrorsElem =  document.getElementById("Errors");

    var Errors= ErrorsElem.options[ErrorsElem.selectedIndex].value;
    var ChangeElem =  document.getElementById("Change");

    var Change= ChangeElem.options[ChangeElem.selectedIndex].value;



   if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="No") {
      x="check your cable is not cut or loose";
} else if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="Both") {
      x="network connections ";
   } else {
      x="other problems....";
   }
   document.getElementById("Solution").innerHTML=x;
}

</script>

Upvotes: 1

Views: 81

Answers (1)

Max Doumit
Max Doumit

Reputation: 1115

   if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="No") {
      x="check your cable is not cut or loose";
} else if (Area=="Yes"||Internet=="Yes"||Errors=="No"||Change=="Both") {
      x="network connections ";
   } else {
      x="other problems....";
   }

The problem is here ! you are using the "or" operator || you should use "and" operator && This should solve it

   if (Area=="Yes"&&Internet=="Yes"&&Errors=="No"&&Change=="No") {
      x="check your cable is not cut or loose";
} else if (Area=="Yes"&&Internet=="Yes"&&Errors=="No"&&Change=="Both") {
      x="network connections ";
   } else {
      x="other problems....";
   }

Upvotes: 3

Related Questions