Sunday, September 17, 2023
Declare Variable in Java-Script
Declare Variable in Java-Script
To declare variable in java-script. The term " var " is used.
Syntax:
var variable name
Code:
< head>
< title>
< /head>
< body>
< /body>
< script>
var number=100
document.write(" The number is " + number)
< /script>
< /html>
Output:
The number is 100
What is concatenation in Java-script?
It is used for combining two or more strings to create a new string.
It allows you to join text or string variables to create a new string.
In java-script the you can concatenate string using the " + " operator.
Here is the example to how's it woks:
< !DOCTYPE html>
< head>
< title>
< /head>
< body>
< /body>
< script>
var num1=10
var num2=20
document.write(" First number is " +num1+ " Second number is " +num2)
< /script>
< /html>
In this example num1 and num2 are concatenated.
Output:
First number is 10 Second number is 20.
How to take data from the user in Java-script?
To take data from the user the term "prompt" is used.
Code:
< head>
< title>
< /head>
< body>
< /body>
< script>
var num1=prompt("enter first number")
var num2=prompt("enter second number")
document.write(" First number is " +num1+ " Second number is " +num2)
< /script>
< /html>
This code will take 2 numbers from the user.
Subscribe to:
Post Comments (Atom)
Digital Clock using html , java , CSS
<! DOCTYPE html > < html lang = "en" > < head > < meta charset = "UTF-8" > < met...
-
Declare Variable in Java-Script To declare variable in java-script. The term " var " is used. Syntax: var variable name Code:...
-
Document Header Tag in HTML Header tag is used for introduction of your content and define top section of ...
No comments:
Post a Comment