dimanche 26 janvier 2020

Javascript code goes through all conditions even when only 1 should be true [closed]

When I attempt to run this program and give it an input, it proceeds to cycle through each IF statement even though only 1 should be able to be true at a time!

<script>
var inputOption = 0;
function runProgram()
{
if (inputOption = 1)
    {alert("1");}

if (inputOption = 2)
    {alert("2");}
if (inputOption = 3)
    {alert("3");}
}
function beginProgram()
{
    var inputOption = prompt("Please choose either 1, 2 or 3!");
    runProgram()
}

</script>

Aucun commentaire:

Enregistrer un commentaire