Write simple JavaScript with HTML for arithmetic expression evaluation and message printing | Client Side Scripting Language (22519)
in this post we are going to learn about client slide scripting 1st practical simple JavaScript with HTML for arithmetic expression
Experiment No: 01 Write simple JavaScript with HTML for arithmetic expression evaluation and message printing.
What is HTML?
|
| Css solved practicals |
What is JavaScript?
Features of JavaScript:
1. Light-weighted and object-based Scripting language2. Case sensitive.
3. Control statement, looping statement
4. Open source and cross Platform
5. Client-side technology
6. Event handling
7. Interpreter based
8. In build function
9. JavaScript is a Scripting language, and it is not Java.
Uses of JavaScript:
Adding JavaScript to Webpage Using <script> tag
To use JavaScript in your program just insert <script> …. </script> tag either in <HEAD>
or <BODY> section of your webpage HTML file.
<script language = “javascript” type=“text/javascript”> /* Javascript code */ </script> Program: /* Hello World program in JavaScript */ <html> <head> <title>First JavaScript Program</title> </head> <body> <script type=”text/javascript”> document.write(“Hello World!”); </script> </body> </html>
Explanation:
1.document.write This statement is used to display the desired message on a web browser.2. Comments in Java: The
// is a single line of comments
The /*…*/ can be used as multi-line comments3. The XHTML
<!--> and <--> is also known as JavaScriptJavaScript can "display" data in different ways:
JavaScript Variables
In a programming language, variables are used to store data values.
JavaScript uses the var keyword to declare variables.
An equal sign is used to assign values to variables.
Arithmetic Operators:
1. Addition (+):-This operator is used to add two operands.2. Subtraction (-):-This operator is used to subtract two operands.
3. Multiplication (*):-This operator is used to multiply two operands.
4. Division (/):-This operator is used to divide two operands.
5. Modulus (%):-This operator is used to check the Remainder.
6. Increment (++):-This operator is used to increment the operand by 1.
7. Decrement (--):-This operator is used to decrement operand by1.
Conclusion:
We understand how to write JavaScript with HTML for arithmetic expression evaluation and message printing.
Exercise:Program Code:
1. Develop a JavaScript program to display the ‘Hello World!’ message in an alert box.Ans:
<html>
<head>
<title> Hello World </title>
</head>
<body>
<script type="text/javascript">
alert("Hello World");
</script>
</body>
</html>
Ans:
<html>
<head>
<title> Hello World </title>
</head>
<body>
<script type="text/javascript">
var a = parseInt(prompt("Enter the vlaue of a: "));
var b = parseInt(prompt("Enter the vlaue of b: "));
var c = a + b;
var d = a - b;
var e = a * b;
var f = a / b;
var g = a % b;
document.write("add is " +c);
document.write("<br>");
document.write("sub is " +d);
document.write("<br>");
document.write("mul is " +e);
document.write("<br>");
document.write("division is " +f);
document.write("<br>");
document.write("mod is " +g);
document.write("<br>");
</script>
</body>
</html>
Questions:
What are JavaScript Data Types?
List any four features of JavaScript.
1. Light-weighted and object-based Scripting language
2. Case sensitive.
3. Control statement, looping statement
4. Open source and cross Platform
5. Client-side technology
6. Event handling
7. Interpreter based
8. In build function
9. JavaScript is a Scripting language, and it is not Java.
2. Case sensitive.
3. Control statement, looping statement
4. Open source and cross Platform
5. Client-side technology
6. Event handling
7. Interpreter based
8. In build function
9. JavaScript is a Scripting language, and it is not Java.
How to declare a variable in JavaScript?
Syntax for declaring the variable:
var variable_name = value;
examplevar Msbte = 5;
What are arithmetic operators?
Arithmetic Operators:
1. Addition (+):-This operator is used to add two operands.
2. Subtraction (-):-This operator is used to subtract two operands.
3. Multiplication (*):-This operator is used to multiply two operands.
4. Division (/):-This operator is used to divide two operands.
5. Modulus (%):-This operator is used to check the Remainder.
6. Increment (++):-This operator is used to increment the operand by 1.
7. Decrement (--):-This operator is used to decrement operand by1.
1. Addition (+):-This operator is used to add two operands.
2. Subtraction (-):-This operator is used to subtract two operands.
3. Multiplication (*):-This operator is used to multiply two operands.
4. Division (/):-This operator is used to divide two operands.
5. Modulus (%):-This operator is used to check the Remainder.
6. Increment (++):-This operator is used to increment the operand by 1.
7. Decrement (--):-This operator is used to decrement operand by1.
Join the conversation