Skip to content

JavaScript user input console

  • by

You need to use the prompt() method to get the user input console. Once you user input as a string and store it on a variable and use it in the console method.

var input = prompt("What is your name?");
console.log(input);

JavaScript user input console

Simple example code.

<!DOCTYPE html>
<html>
<body>

  <script>
   var input = prompt("What is your name?");

   console.log(`Your name is ${input}`);
 </script>

</body>
</html>

Output:

JavaScript user input console

Do comment if you have any doubts or suggestions on this Js console topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading