Get number from user input and display in console with JavaScript

You can use # to get the value when user clicks the button using document.querySelector(""); Following is the JavaScript code ?

Example





Document





Example: choose a number between 1 to 100

To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.

Output

Add a value ?

On clicking the button Click Me, the same is visible in Console ?


Updated on: 2026-03-11T22:50:50+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements