How to Code an Alert with a Variable Using Javascript
Write the first line of code., Write the next line of code., Add in more variables if you want.
Step-by-Step Guide
-
Step 1: Write the first line of code.
Type "var name = prompt ('What is your name?')".
Replace "name" with whatever you want to call your variable.
Replace "What is your name?" with whatever you want to ask for. , Type "alert ('Heya, ' + name + '! ')".
This line of code will add the variable "name" to the words "Heya, ! ".
For example, if the user inputs "Trevor" as the value of the variable "name"
the alert will say "Heya, Trevor! ".
You can use any message you want, though.
If your variable is "favoriteColor" and "Blue" is the value, for instance, you can have the alert say "Blue is a very nice color! "
Try to make a one or two sentence biography. -
Step 2: Write the next line of code.
-
Step 3: Add in more variables if you want.
Detailed Guide
Type "var name = prompt ('What is your name?')".
Replace "name" with whatever you want to call your variable.
Replace "What is your name?" with whatever you want to ask for. , Type "alert ('Heya, ' + name + '! ')".
This line of code will add the variable "name" to the words "Heya, ! ".
For example, if the user inputs "Trevor" as the value of the variable "name"
the alert will say "Heya, Trevor! ".
You can use any message you want, though.
If your variable is "favoriteColor" and "Blue" is the value, for instance, you can have the alert say "Blue is a very nice color! "
Try to make a one or two sentence biography.
About the Author
Thomas Gray
A passionate writer with expertise in creative arts topics. Loves sharing practical knowledge.
Rate This Guide
How helpful was this guide? Click to rate: