How to Take User Input in JavaScript: Prompt and HTML Input Methods | Javascript | Web Development

preview_player
Показать описание
In this tutorial, you'll learn two easy methods for taking user input in JavaScript and printing it to the console. We’ll start by using the built-in prompt function, which allows you to capture input through a simple dialog box that pops up on the screen. This method is great for quick testing or for small projects where you just need a single piece of input from the user.

Next, we’ll explore a more interactive approach using HTML. We’ll create a simple text input field and a button. When the button is clicked, it triggers a function that captures whatever text the user entered and displays it in the console. This approach is more versatile and commonly used in web applications, as it allows you to design a user-friendly input form directly on the page.

By the end of this short video, you’ll have a clear understanding of both methods and be able to decide which one fits best for your own projects.
Рекомендации по теме
Комментарии
Автор

Method 1
let x;
prompt("Enter the value");
console.log(x);


Method 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accepting users input</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<label for="text">Enter what you want to enter</label>
<input type="text" id="text">
<button id="button">Print on console</button>
<script src="script.js"></script>
</body>
</html>
let input =
let button =

, () => {
console.log(input.value)
})

InformalCoding
welcome to shbcf.ru