take info from user input in javascript

To take information from a user in JavaScript, you can use the prompt() function. The prompt() function creates a dialog box that displays a message and a text input field for the user to type in their response. Here is an example:

index.tsx
let userInput = prompt("Please enter your name:");
console.log("Hello, " + userInput + "!");
93 chars
3 lines

In this example, the prompt() function is called with a string argument that serves as the message displayed to the user. The user's response is stored in the userInput variable, which can then be used in the rest of your code.

Note that the prompt() function returns a string, even if the user enters a number. You may need to parse the user's input as a number using parseInt() or parseFloat() depending on your needs.

gistlibby LogSnag