How to Code an Alert with a Variable Using Javascript
Alerts with variables are among the most useful things in javascript coding. You can use them to refer to someone by their name, to make a mini MadLibs game, or even for showing quiz results. This article will show you how to make a...
Table of Contents
Part 1 of 2:
Setting Up the Variable
- Write the first line of code. Type "var username = prompt ('What is your name?');". Replace "username" with whatever you want to call your variable. Replace "What is your name?" with whatever you want to ask for.
Part 2 of 2:
Making the Alert
-
Write the next line of code. Type "alert ("Hey, " + name + "!");". This line of code will add the variable "name" to the word "Hey, "(with the space at the end), and then add "!" to end the sentence (not required). 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! " - Add in more variables if you want. Try to make a one or two sentence biography.
3.7 ★ | 3 Vote
Read More
- Instructions on running Node JavaScript code in n8n
- JavaScript code to generate error charts & graphs
- What is Currying in Javascript? How to use Currying in JavaScript
- Syntax of JavaScript
- JavaScript code that generates box and whisker charts containing outliers
- JavaScript code to create bubble charts and graphs.
- JavaScript code to create a combined area and line chart.
- JavaScript code to generate dynamic line graphs/charts
- JavaScript code to create a chart/graph combining lines, areas, and columns.
- JavaScript code to generate box and whisker charts/graphs
- Sample JavaScript code to create a chart with a second axis.
- JavaScript code to create a scatter plot/point chart
- JavaScript code to generate error line graph/graph
- JavaScript location in HTML File