+ 1

Please How can I get a user's input/reply in .js

29th Oct 2020, 5:07 PM
Ikechukwu Francis
Ikechukwu Francis - avatar
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;
29th Oct 2020, 11:06 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 4
There are lots of way you can take input from user but the simplest way is using prompt method Example let a = prompt();
29th Oct 2020, 5:21 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 3
Thanks allot ❣️
30th Oct 2020, 10:08 AM
Ikechukwu Francis
Ikechukwu Francis - avatar
+ 2
You simply store that value in some variable Example let a = prompt() console.log(a)
29th Oct 2020, 6:09 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
After prompting the user, how can I get their reply on console???
29th Oct 2020, 6:02 PM
Ikechukwu Francis
Ikechukwu Francis - avatar
+ 1
Russ thanks for correction
29th Oct 2020, 6:07 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Use prompt( )for getting user input Var text=prompt ( ) console.log(text ) Prints whatever user enters
29th Oct 2020, 10:05 PM
Atoms~⚛
Atoms~⚛ - avatar