I am creating a very simple story based "game" where there is a question with choices (not radio buttons etc) and the user has to type in the choices that's been given to them. I am not very good with JavaScript as you will see...
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="gamescript.js"></script>
</head>
<body>
<p id ="door"> Which door do you wish to enter? Door 1 or Door 2? </p>
<input id="myInput" type="text">
<button onclick="myFunction()">Enter</button>
<script>
function myFunction(){
var door = document.getElementById("myInput").value;
if (door == "Door 1", "door 1"){
document.getElementById("door").innerHTML = "You have entered" + door;
}else if (door == "Door 2", "door 2"){
document.getElementById("door").innerHTML = "You have entered" + door;
}else{
document.getElementById("door").innerHTML = "You must enter a door!"
}
}
</script>
</body>
</html>
I am not getting any errors but when I type in something random/or leave blank, it's meant to say "Choose a door" but it's displaying anything i type into the text box. This code might be wrong, i'm guessing it most likely is..I didn't want to come online for help but have no one else to ask. All help is appreciated. Thank you.
door == "Door 1", "door 1"<-- learn what the comma operator does. It does not do what you think it does.