Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introduction to Programming Basics Comments

alert vs prompt

What's the difference between alert and prompt?

The alert() dialog box is used to communicate a message to the user (generally warnings of missed actions). For example, if the email address entered is wrong, you can use the alert() message to warn the user about it. Developers also use alerts() as a quick and dirty way to debug their applications.

The prompt() method asks the user for some small input such as a password, completion of a form input, or personal information, such as nickname or title. The prompt dialog box pops up with a simple text box. After the user enters text into the prompt dialog box, its value is returned (or null in case the user hit cancel).

2 Answers

Richard Duncan
Richard Duncan
5,568 Points

Hi Lloyd,

An alert is a popup that has a notice within it.

A prompt has an input field and expects the user to interact with it by entering some data.

Here's a demo

Ah, of course. I think it's time to take a break and get some coffee...

Richard Duncan
Richard Duncan
5,568 Points

Lloyd Lee No worries :) I've been on the go approaching 10 hours, I know how you feel!

Alert will print something on the screen( data from the the from the programmer) . Prompt takes in data from the user and returns it. This can then be stored in a variable to be used else where in the program.