Level no.23
JAVA-SCRIPT
Lecture #1
Java-script is widely used programming language used for web developers.It is object-oriented programming language used my developers to make wed pages interactive. It is used for creating dynamically updated content. Java-script is used for animated graphics.
Syntax:
<!DOCTYPE html>
<head>
<title></title>
</head>
<body>
</body>
<script>
document.write(" enter your text here ")
</script>
</html>
document.write(" ") is used in java-script for printing text on screen. This term is written between <script> </script>.
Code:
<!DOCTYPE html>
<head>
<title></title>
</head>
<body>
</body>
<script>
document.write(" Hello Coding ")
</script>
</html>
Output:
Hello Coding
Declare Variable in Java-Script
To declare variable in java-script. The term " var " is used.
Syntax:
var variable name
Code:
<!DOCTYPE html>
<head>
<title></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 you can concatenate string using the " + " operator. Here is the example to how's it woks:
<!DOCTYPE html>
<head>
<title></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:
<!DOCTYPE html>
<head>
<title></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.
Amazing work
ReplyDelete