Well this is what happen's when you add plus before prompt, i.e. as below,

Eg :- 1

var a = prompt("Please enter a number");
console.log(a);
typeof(a);

Now in eg (1) when you enter a number and if you check that in console, it show a number but as that number is in-between double-quote, so in JavaScript it's a string, that's what it will show in typeof too when you console that.

Eg :- 2

var a = +prompt("Please enter a number");
console.log(a);
typeof(a);

Now when you console the var a and typeof a of eg(2) the result differs as we have added + before prompt. So this time we get our prompt input value as number and not string. Try you will understand what I'm saying.

Answer from frnt on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Window โ€บ prompt
Window: prompt() method - Web APIs | MDN
window.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ met_win_prompt.asp
Window prompt() Method
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Discussions

+prompt vs prompt in JavaScript - Stack Overflow
Is it good to use +prompt instead of just regular prompt in JavaScript if I want only integer numbers to be typed in my prompt window? Does it say something like that about +prompt in the JavaScript More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to store user input using prompt() in JavaScript? - Stack Overflow
If I were to have a prompt in my code like this: prompt("What is your favorite animal?"); Is there a way to store the answer? More on stackoverflow.com
๐ŸŒ stackoverflow.com
prompt function in JS ? (Eloquent JavaScript book)
prompt only works in browser. If you're trying to run this in node or such, it won't be found More on reddit.com
๐ŸŒ r/learnjavascript
10
1
May 14, 2021
JavaScript Prompt() method - Stack Overflow
I have an assignment I'm working on and I am having a problem with the prompt() method. I see that I can do one prompt, but I need several and with amounts. For Example... I have created an HTML... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ javascript โ€บ window โ€บ prompt()
JavaScript | window | prompt() | Codecademy
February 20, 2025 - The prompt() function is a built-in JavaScript method that displays a modal dialogue box prompting the user for input. It is part of the Web API, provided by the browserโ€™s window object, and pauses script execution until the user responds.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-window-prompt-method
Javascript Window prompt() Method - GeeksforGeeks
August 5, 2025 - The window.prompt() method in JavaScript is a built-in function that displays a dialog box prompting the user to input some text.
๐ŸŒ
JavaScript.info
javascript.info โ€บ tutorial โ€บ the javascript language โ€บ javascript fundamentals
Interaction: alert, prompt, confirm
let age = prompt('How old are you?', 100); alert(`You are ${age} years old!`); // You are 100 years old!
Find elsewhere
๐ŸŒ
SheCodes
shecodes.io โ€บ athena โ€บ 90671-what-is-prompt-in-javascript-how-to-use-it
[JavaScript] - What is prompt in JavaScript? How to use it? | SheCodes
Learn about the prompt function in JavaScript, its usage, and how to use it to get user input and store it as a string.
๐ŸŒ
SheCodes
shecodes.io โ€บ athena โ€บ 1491-how-to-use-prompt-if-else-in-javascript
[JavaScript] - How to Use Prompt & If Else in JavaScript - | SheCodes
Learn how to create a prompt question with different spelling answers using JavaScript, using the `prompt()` function to ask the user a question, followed by the `if...else` command.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ tryit.asp
W3Schools Tryit Editor - JavaScript Prompt
The W3Schools online code editor allows you to edit code and view the result in your browser
๐ŸŒ
Medium
medium.com โ€บ @meghamurari12 โ€บ lesson-16-user-input-with-prompt-in-javascript-df46a299ecab
๐Ÿ“˜ Lesson 16: User Input with prompt() in JavaScript | by Meghamurari | Medium
August 9, 2025 - The prompt() function in JavaScript displays a dialog box that prompts the user for input. It's a simple way to interact with users andโ€ฆ
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ prompt
prompt - npm
$ node examples/simple-prompt.js prompt: username: some-user prompt: email: some-user@some-place.org Command-line input received: username: some-user email: some-user@some-place.org
      ยป npm install prompt
    
Published ย  Apr 11, 2022
Version ย  1.3.0
Author ย  Nodejitsu Inc.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ javascript window.prompt() method
JavaScript Window.prompt() Method - Scaler Topics
May 4, 2023 - window.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ prompt function in js ? (eloquent javascript book)
r/learnjavascript on Reddit: prompt function in JS ? (Eloquent JavaScript book)
May 14, 2021 -

Hi there,

I started to teach my self JS via the book " Eloquent JavaScript"

I encounter the use of prompt function in the book, which I understand is suppose to take an input from the user (similar to 'scanf' in C (?))

I'm using Visual Studio Code. When I try to run this code:

let theNumber = Number(prompt("Pick a number"));
if (!Number.isNaN(theNumber)) {
console.log("Your number is the square root of " +
theNumber * theNumber);
}

I'm getting an error message: "ReferenceError: prompt is not defined"

How can I use to "prompt" function in JS ?

Thanks for helping!

๐ŸŒ
Flexiple
flexiple.com โ€บ javascript โ€บ javascript-window-prompt
JavaScript Window prompt() Method - Flexiple
April 23, 2024 - The JavaScript Window prompt() method displays a dialog box that prompts the visitor for input. A prompt dialog box shows a specified message, providing an input field for the user to enter a string of text and allowing for a default answer ...
๐ŸŒ
BitDegree
bitdegree.org โ€บ learn โ€บ javascript-prompt
Guide on JavaScript Prompt Method: JavaScript Prompt Box Explained
September 8, 2017 - The JavaScript prompt() method is commonly used for prompting the user for input before entering a web page.
Top answer
1 of 4
5

From the sounds of it, the following meets your requirements:

var a, d, t;

while ( ! a ) a = prompt( "Which Artist?" );
while ( ! d ) d = prompt( "How many DVDs?" );
while ( ! t ) t = prompt( "How many tapes?" );

alert( "You want " + t + " Tapes, and " + d + " DVDs, of " + a + "." );

Let's break it down you so have an understanding of what's going on:

var a, d, t;

On the first line, I'm declaring the various variables I plan on using in the code below. This is a common practice, and would be a good habit to develop if you want to maintain clean and manageable code.

while ( ! a )

The while loop is a loop that will run over and over, until a condition is met. In this example, we're telling the loop to run as long as we don't have a value for a. What comes next is our attempt to collect a value of a from the user:

while ( ! a ) a = prompt( "Which Artist?" );

Each time the while loop runs, we will prompt the user to answer the question. We take their answer, and assign it to a. If they entered nothing, our while loop runs again, prompting them again. You can probably make sense of the next two while loops at this point.

Lastly is our alert, which gathers up the various values and shows them to the user:

alert( 'Artist ' + a );

This also presents an example of string concatenation, or joining together of two strings. We have a value stored inside a, and a value written explicitly as text. We use the + operator to join both of these together, like glue tying two ends of a rope together. As we add more strings, and more variables, we use the + operator more and more:

alert( "You want " + t + " Tapes, and " + d + " DVDs, of " + a + "." );

When this code is ran, t, d, and a will all be replaced with the actual values inserted by the end-user.

Note, this is a very basic implementation of what your homework requires. A real solution would test the type of input to make sure it's of the expected format. For instance, when asking how many DVDs the user wants, you may want to restrict 'acceptable' answers to integers only.

Best of luck!

2 of 4
2

Use a loop over the values object/array. Maybe use a second (nested) loop to prompt again until a value was entered.

๐ŸŒ
Dummies
dummies.com โ€บ article โ€บ technology โ€บ programming-web-design โ€บ javascript โ€บ how-to-prompt-the-user-for-input-in-javascript-140912
How to Prompt the User for Input in JavaScript | dummies
July 3, 2025 - To store userโ€entered data in a variable, you create a new variable and then follow it with =. You then follow it with the prompt statement. ... It's important to note that a single equal sign (=) in JavaScript is called the assignment operator.