Using JavaScript to make all text lowercase

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.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

you want to get the value of this element.

to get the value, just do element.value (as in, add .value to the method chain)

1 Like

On a quick look i spotted that. And note that some fonts cannot be converted to lowercase…using .toUpperCase() is probably better