+ 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
3 Réponses
+ 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();
+ 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?";
}
0
Hey Mohammed you can also use form to get input
https://code.sololearn.com/WbzKYHDNAxYs/?ref=app