I am trying to make a simple program that allows me to check input of a form is a valid "command" and send "return";
However, my code doesn't work. Can someone please help me? The problem is that even when I type help or ping it thinks it's incorrect and does the alert and location.reload(); HTML:
const commands = [{
command: 'help',
return: 'there is no help'
},
{
command: 'ping',
return: 'pong lol'
},
];
function sendCommand(x) {
var commandReturn = document.getElementById("commandReturn");
if (commands.includes(x) == true) {
let returnable = commands.includes(x).return;
commandReturn.innerHTML += (returnable + "<br>");
} else {
console.log("Incorrect command, restarting...")
location.reload();
}
}
<div id="commandReturn">
</div>
<form onSubmit='document.getElementById("input").value=""; sendCommand(this);'>
<input method="post" name="command" placeholder="_" id="input">
</form>