How do i take input in javasscript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do i take input in javasscript

I know there is a input method by using prompt() But when i solve code coach, i usually find out that the input fuction is already written by a function=> readline() But when i use it , it does not work

27th Aug 2023, 12:19 PM
Mohammed Mahbeer Rahman
Mohammed Mahbeer Rahman - avatar
3 Answers
+ 3
The prompt() function: This function displays a dialog box that prompts the user for input. The input value is returned as a string. The readline() function: This function reads a line of text from the user's input. The input value is returned as a string. The readline() function is a newer function that is not supported by all browsers. If you are using an older browser, you will need to use the prompt() function. If you are using Code Coach, you need to make sure that the input function is defined in the code. The input function is usually defined at the top of the code, like this: function readline() { // This function reads a line of text from the user's input. var input = prompt(""); return input; } var name = readline();
27th Aug 2023, 12:32 PM
Sreeju
Sreeju - avatar
+ 3
Window prompt() https://www.w3schools.com/jsref/met_win_prompt.asp let person = prompt("Please enter your name", "Harry Potter"); if (person != null) { document.getElementById("demo").innerHTML = "Hello " + person + "! How are you today?"; }
27th Aug 2023, 12:24 PM
SoloProg
SoloProg - avatar
0
Hey Mohammed you can also use form to get input https://code.sololearn.com/WbzKYHDNAxYs/?ref=app
28th Aug 2023, 2:40 PM
Winnie Otieno