How to Code an Alert with a Variable Using Javascript
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
You should read it
May be interested
- Summary of JavaScript exercises with sample codein order to make your javascript learning easier, tipsmake.com has compiled a number of javascript exercises with sample solutions for you to practice.
- JavaScript code to create multi-series graphs that update live datathe example below illustrates a multi-series line chart pattern that is updated every 3 seconds. it is created with javascript.
- JavaScript code to create box & whisker chart/graph templates with custom colorsthe example below illustrates a box & whisker chart template with customizable colors for the top and bottom boxes created with javascript.
- JavaScript code to create bubble chart with custom markerthe example below shows a bubble chart with a customized highlight style and javascript source code that you can edit in your browser or save to your device to run locally.
- How to Debug Javascriptthe ability to debug code is an essential tool in any programmer's arsenal. debugging will give you inside information into how your program is functioning, in real-time, as it runs. javascript offers a unique but familiar method of...
- JavaScript code to create Pareto charts & graphsthe example below illustrates a pareto chart template created with javascript. you will also have the source code to edit in the browser or save to your computer to run locally.
- Code of chart/bar graph with error combinationthe example below illustrates a bar chart template with errors created with javascript.
- JavaScript code to create OHLC and line chart combo chart templatethe example below illustrates a sample of the 2016 lockheed martin stock price chart with the number of shares by combining the ohlc and line graphs.
- JavaScript code that generates Pareto chart template with Index/Data . labelyou can easily add and customize index/data labels to the pareto chart. the example below shows a pareto chart with data/index labels created with javascript.
- Array (Array) in JavaScriptarray object - array helps you store multiple values in a single variable. it stores a set of fixed-size ranges of elements in the same type (type). an array is used to store a data set, but it is often more useful to think of an array as a collection of variables in the same type.