Home > OS >  How to Receive Data from JavaScript?
How to Receive Data from JavaScript?

Time:09-19

I want to learn/know how to get or receive data inputted through my prompt? For example, I wanted to receive data from my restaurant menu from customers. How would I be able to do that, if possible, in javascript?

CodePudding user response:

All you need is:

const result = prompt("What is your name?");
console.log(result);

CodePudding user response:

The prompt box/function resembles the input function in Python; the function returns the entry user, well, entered. So you should declare the function as a variable:

var username = prompt("Username?"); 

and the username equals what the user has entered.

A note: username would be equal to null if the user refuses to enter anything and would be equal to "" if the user just clicks on "OK".

You can also have a default value for the prompt like this:

var username = prompt("Username?", "@Example")
  • Related