CSS - Practical No 1
CSS - Practical No 1
1 :
I .Aim: Write simple JavaScript with HTML for arithmetic expression Evaluation and
message printing.
Types of Operator:
JavaScript supports the following Arithmetic Operators:
* Multiplication c=a*b
/ Division c=a/b
% Modulus c=a%b
++ Increment a++
-- Decrement a--
1. Alert Dialog Box : An alert dialog box is mostly used to give a warning message to the users.
For example, if one input field requires to enter some text but the user does not provide any
input, then as a part of validation, you can use an alert box to give a warning message.
3. Prompt Dialog Box: The prompt dialog box is very useful when you want to pop-up a text
box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the
field and then click OK. This dialog box is displayed using a method called prompt() which takes
two parameters: (i) a label which you want to display in the text box and (ii) a default string to
display in the text box.This dialog box has two buttons: OK and Cancel. If the user clicks the OK
button, the window method prompt() will return the entered value from the text box. If the user
clicks the Cancel button, the window method prompt() returns null.
Syntax: var retVal = prompt("Enter your name : ", "your name here");
III. Result :
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
IV. Conclusion(s)
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
V. Questions:-
1) State the features of JavaScript.
1. It is a light-weighted and interpreted language.
2. It is a case-sensitive language.
6. All popular web browsers support JavaScript as they provide built-in execution
environments.
7. JavaScript is an object-oriented programming language that uses prototypes
rather than using classes for inheritance.
9. Platform Independent.
10. It supports Client-Side Validation
<body>
<script>
alert( 'Hello, world!' );
</script>
</body>
</html>
var a=10;
var b=20;
</script>
II. Multi line comments
Multi-line comments start with /* and end with */.
<script>
VI. Exercise:-
1. Write a program to read arithmetic expressions from the user, evaluate it and display the
answer using an alert box.
<html>
<head>
<title>evaluate expression</title>
<head>
<body>
<script type="text/javascript">
var exp= prompt("Enter the expression");
var evaluate= eval(exp);
alert(evaluate);
</script>
</body>
</html>