+ 1
Please How can I get a user's input/reply in .js
7 odpowiedzi
+ 1
Ikechukwu Francis ,
If you aim to use the prompt and use the result in some way, don't forget to consider that the result of a prompt is of string type (even if you enter a number).
So if you need the user to enter a number to use it in a calcul, you will have to convert it as a number type first.
You can either use :
let userInput = Number(prompt("enter a number :");
Or
let userInput = +prompt("enter a number :");
Or keep the string type and convert the result later, same ways
let userInput = prompt("enter a number :");
let userNumber= Number(userInput);
or
let userNumber = +userInput;
+ 4
There are lots of way you can take input from user but the simplest way is using prompt method
Example
let a = prompt();
+ 3
Thanks allot ❣️
+ 2
You simply store that value in some variable
Example
let a = prompt()
console.log(a)
+ 1
After prompting the user, how can I get their reply on console???
+ 1
Russ thanks for correction
+ 1
Use prompt( )for getting user input
Var text=prompt ( )
console.log(text )
Prints whatever user enters