0
0
Javascriptprogramming~15 mins

Basic input concepts (prompt overview) in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic Input Concepts with prompt() in JavaScript
📖 Scenario: You are creating a simple webpage that asks the user for their favorite fruit and then shows a message with their answer.
🎯 Goal: Build a small program that uses prompt() to get user input and then displays it using alert().
📋 What You'll Learn
Use prompt() to ask the user for their favorite fruit
Store the input in a variable called favoriteFruit
Create a message string that says "Your favorite fruit is: " followed by the input
Use alert() to show the message
💡 Why This Matters
🌍 Real World
Getting input from users is common in web pages for surveys, forms, or interactive tools.
💼 Career
Understanding how to collect and use user input is a basic skill for web developers and software engineers.
Progress0 / 4 steps
1
Create a variable to store user input
Write a line of code that uses prompt() to ask the user "What is your favorite fruit?" and store the answer in a variable called favoriteFruit.
Javascript
Need a hint?

Use const favoriteFruit = prompt("What is your favorite fruit?"); to get the input.

2
Create a message string with the input
Add a line of code that creates a variable called message and sets it to the string "Your favorite fruit is: " followed by the value of favoriteFruit using a template literal.
Javascript
Need a hint?

Use a template literal like `Your favorite fruit is: ${favoriteFruit}` to create the message.

3
Show the message using alert()
Write a line of code that uses alert() to display the message variable.
Javascript
Need a hint?

Use alert(message); to show the message to the user.

4
Run the program and see the output
Run the program and enter "Apple" when prompted. The alert should show the message "Your favorite fruit is: Apple". Write a line of code that calls alert(message) to display the message.
Javascript
Need a hint?

When you run the code and type "Apple" in the prompt, the alert should show "Your favorite fruit is: Apple".