I am learning JavaScript for fun and I am creating a text based adventure game. So far the code I have works. However, I want the user to type in commands that I want formatted to lowercase. I have tried to follow online examples but I must be missing something. I have tried typing both lowercase and uppercase text but this does not get a response that I created.
The HTML code: The input for text.
<input id="instring" type="text">
<input type="button" value="Click to send reply" onclick="acts(txt);">
If the correct text is used, the innerHTML of instring is changed to a new message - but not in this case.
The function:
function acts(txt) {
negativeText1 = " You cannot do that! ";
negativeText2 = " That command is not understood. Try something else.! ";
text = document.getElementById('instring').toLowerCase();
switch(text) {
case 'help':
document.getElementById('instring').innerHtML = "Try looking at something.";
break;
default:
document.getElementById('instring').innerHtML = negativeText2;
}
}
I am sort of new to javaScript, but would appreciate and help, with examples if possible.