parseInt() or parseFloat() are functions in JavaScript which can help you convert the values into integers or floats respectively.

Syntax:

 parseInt(string, radix);
 parseFloat(string); 
  • string: the string expression to be parsed as a number.
  • radix: (optional, but highly encouraged) the base of the numeral system to be used - a number between 2 and 36.

Example:

 var x = prompt("Enter a Value", "0");
 var y = prompt("Enter a Value", "0");
 var num1 = parseInt(x);
 var num2 = parseInt(y);

After this you can perform which ever calculations you want on them.

Answer from Anurag-Sharma on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ met_win_prompt.asp
Window prompt() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS
Discussions

asking user input with prompt to provide the numbers
Liga Zarina is having issues with: I did the code challenge like Dave showed in the video by putting the random numbers in the code when calling the function and it worked as it s... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
2
August 14, 2016
javascript prompt number and continue prompting if answer is wrong - Stack Overflow
I need prompt the visitor for an integer between 1 and 100 and to continue prompting until a valid number is entered. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Input as number in JavaScript prompt - Stack Overflow
Can we customize a prompt box in JavaScript so it takes time as input? var r = prompt("ENTER THE NUMBER OF SECONDS AFTER WHICH YOU WANT TO BE REMINDED"); More on stackoverflow.com
๐ŸŒ stackoverflow.com
html - Javascript prompt/textbox only numbers - Stack Overflow
Hey guys I'm just learning javascript, I have some html and css background though. I can't figure out how to allow only number values to be entered into a prompt, or check if its a number or not t... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ how do i get the value (numeric) of the prompt box??
r/learnjavascript on Reddit: how do I get the value (numeric) of the prompt box??
September 2, 2024 -

Hello everyone.

I am currently doing a project on the Odin Project and I need to get the value (numeric) of the prompt box which pop-ups with a button click.

I searched a bit how to this online and I think that I can use the value property for getting the value and I also found out that the return value of the prompt is always string and I need to use parseInt property for converting string to number.

So, I came up with the code below, but I didn't get the prompt box after I click the button

=>

const
 btn = document.querySelector("button");

    btn.addEventListener("click", () 
=>
 {

        
const
 input = parseInt.prompt("Enter the number of squares of the new grid").value;

      
    })

and then I tried this and this time I get the prompt box

=>

const
 btn = document.querySelector("button");

    btn.addEventListener("click", () 
=>
 {

        
const
 input = prompt("Enter the number of squares of the new grid");

        
const
 newinput = parseInt.input.value;

    })

but I am not really sure whether I really get the value ( I mean store it in the variable).

Can you give me feedback about this?

I need this prompt value as I will use it change the div numbers in the page based on the entered number.

I am providing my codepen: https://codepen.io/albert9191/pen/vYqVLvJ

๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Window โ€บ prompt
Window: prompt() method - Web APIs | MDN
A prompt dialog contains a single-line textbox, a Cancel button, and an OK button, and returns the (possibly empty) text the user entered into that textbox. The result is a string, which means you should sometimes cast the value given by the user. For example, if their answer should be a Number, you should cast the value to Number.
๐ŸŒ
Rouvelle
rouvelle.com โ€บ javaScript_strings_to_numbers.htm
JavaScript: Prompts and turning Strings in Numbers using parseInt() and parseFloat()
The problem with the prompt() instruction is it always returns a string. If we used it to get two numbers from the user and add them, we are going to run into problems: <SCRIPT LANGUAGE="JavaScript"> var first_number = prompt("Enter the first number", ""); var second_number = prompt("Enter the second number", ""); var answer = first_number + second_number; document.write("The answer is " + answer); </SCRIPT> If you enter 3 for the first number and 5.6 for the second, you should get the answer 8.6, but in fact you get the answer 35.6.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2756370 โ€บ how-to-check-if-a-prompt-is-a-number
How to check if a prompt is a number? | Sololearn: Learn to code for FREE!
let pro = +prompt('Type a number!, 0); // unary + convert it to a number if(isNaN(pro)) { // NaN means Not a Number check if it is alert('It is not a number'); } else { // Here it is a number }
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ watch
Javascript Tutorial - Using the prompt() and Number() functions - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published ย  February 7, 2013
๐ŸŒ
Webdevelopersnotes
webdevelopersnotes.com โ€บ the-javascript-prompt-getting-user-input
The JavaScript prompt โ€“ Getting user input
var n = prompt("Check your number", "Type your number here"); n = parseInt(n); if (isNaN(n)) { alert("The input cannot be parsed to a number"); } else { if (n == 0) { alert("The number is zero"); } else if (n%2) { alert("The number is odd"); ...
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2952070 โ€บ javascript-user-input-solved
JavaScript User Input [SOLVED] | Sololearn: Learn to code for FREE!
When you say prompt() it returns a string by default. You must cast the value to a number type and you can either use: Number(prompt()) or parseInt(prompt()). Strings see '+' as concatenating operator.
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 530ae12b282ae36a28000cb7
When using the prompt method does it store as a String or number type? | Codecademy
So as you can see the returned result of prompt is always a string. That is not ultimately harmful for using numbers as input, but you need to be careful. Comparing numbers is still possible, but only with == (compare value), === wonโ€™t work as it measn โ€œcompare value and typeโ€ and โ€œ42โ€ and 42 have the same value but a different type (number vs string).
๐ŸŒ
YouTube
youtube.com โ€บ watch
JavaScript Prompt Explained โ€“ How to Get User Input Easily - YouTube
This video introduces the JavaScript prompt(), parseInt() and parseFloat() functions - three essential tools for getting user input and converting it to numb...
Published ย  May 6, 2025
๐ŸŒ
IncludeHelp
includehelp.com โ€บ code-snippets โ€บ input-value-from-the-user-using-prompt.aspx
JavaScript | Input value from the user using prompt
<!DOCTYPE html> <HTML> <HEAD> <SCRIPT> ... To input numbers i.e., integer values in JavaScript using the text boxes, you need to parse the input value because the text box returns the string....
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 47649426 โ€บ input-as-number-in-javascript-prompt
Input as number in JavaScript prompt - Stack Overflow
Alternatively you could verify the user's input yourself and stick with prompt like this: // need a way to check if input is a valid number var isNumber = Number.isInteger || function(number){ return !isNaN(parseFloat(n)) && isFinite(n) } var ...
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 53bc71d78c1ccca3d300045a
what kind of data can prompt() give? and does the information from confirm() count as boolean? | Codecademy
The user may input a number, but prompt() casts it as string type. When we feed data directly from prompt() to a statement meant for numbers, like comparing, (age > 13) there is a type mismatch but JavaScript graciously accepts this and triggers ...
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 5575df34937676a0b50000e8
Does prompt always come back as a string that you have to convert? | Codecademy
Yes, except when it doesnโ€™t. prompt() always returns a string, whether numbers or characters, with one exception.