0

Prompt (JavaScript) in "if"

Is it possible to put a prompt in, for instance, an "if" statement (or whatever they are called)? If so, how? What about a "function?"

10th Jan 2018, 3:04 AM
YoBoi
3 Antworten
- 1
It definitely is possible! To put one in an if statement, you would just do the following: if(statement){ x = prompt("Enter a number!"); } This will only prompt the user if the statement is true. The same can be done with functions: function func(x){ x = prompt("Enter a number!"); return x; } var user; document.write(func(user));
10th Jan 2018, 3:13 AM
Faisal
Faisal - avatar
0
Thank you!
10th Jan 2018, 3:29 AM
YoBoi
- 1
No problem! 👍😉
10th Jan 2018, 3:36 AM
Faisal
Faisal - avatar