Does anyone know how to get user input?

I’m quite new to java script, and can’t figure out how to get user input.

There are different types of user input. I’m going to assume that you mean typing in a string of text. On that basis this gets some text from the user and outputs it to the console.


async function prompt(p_strMsg)
{
	let getText = new Alert();
	getText.message = p_strMsg
	getText.addTextField();
	getText.title = "Enter text";
	getText.addAction("OK");
	getText.addCancelAction("Cancel");
	let result = await getText.present();
	if (result == -1)
	{
		return null;
	}
	else
	{
		return getText.textFieldValue(0);
	}
}

console.log(await prompt(""));

Hope that helps.

Is it possible to use the text that was entered in another line of code??

Thank you. That was very helpful.

Yes.

Replace the last line with this as an example to use the input twice in different ways (output in mixed case as entered and then all in lower case). You just need to store the result of the prompt in a variable.

let strInput = await prompt("");
console.log(strInput);
console.log(strInput.toLowerCase());