0% found this document useful (0 votes)
57 views

CSS - Practical No 1

The document discusses writing simple JavaScript programs with HTML for arithmetic expression evaluation and message printing. It provides details about arithmetic operators, dialog boxes in JavaScript, and includes sample code to evaluate expressions and print messages. It also asks questions about JavaScript features and writing comments. Finally, it provides an exercise to read expressions from the user and evaluate them using alert boxes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

CSS - Practical No 1

The document discusses writing simple JavaScript programs with HTML for arithmetic expression evaluation and message printing. It provides details about arithmetic operators, dialog boxes in JavaScript, and includes sample code to evaluate expressions and print messages. It also asks questions about JavaScript features and writing comments. Finally, it provides an exercise to read expressions from the user and evaluate them using alert boxes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No.

1 :

I .Aim: Write simple JavaScript with HTML for arithmetic expression Evaluation and
message printing.

II. Minimum Theoretical Background

Arithmetic Expressions: An operator, in computer programming, is a symbol that usually


represents an action or process. These symbols were adapted from mathematics and logic. An
operator is capable of manipulating a certain value or operand. Arithmetic operators perform
Arithmetic Operations on numbers (literals or variables).

Types of Operator:
JavaScript supports the following Arithmetic Operators:

Operator Meaning Example

+ Addition or Unary plus c=a+b

- Subtraction or Unary minus d=-a

* Multiplication c=a*b

/ Division c=a/b

% Modulus c=a%b

++ Increment a++

-- Decrement a--

Dialog Boxes in JavaScript:


The following dialog boxes are supported by Javascript

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.

Syntax: alert ("This is a warning message!");


2. Confirmation Dialog Box: A confirmation dialog box is mostly used to take the user's
consent on any option. It displays a dialog box with two buttons: OK and Cancel. If the user
clicks on the OK button, the window method confirm() will return true. If the user clicks on the
Cancel button, then confirm() returns false.

Syntax: var retVal = confirm("Do you want to continue ?");

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.

3. JavaScript is supportable in several operating systems including, Windows,


macOS, etc.

4. It provides good control to the users over the web browsers.

5. JavaScript is an object-oriented programming language that uses prototypes


rather than using classes for inheritance.

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.

8. It supports Dynamic Typing.

9. Platform Independent.
10. It supports Client-Side Validation

2) How to write a Hello World example of JavaScript?


<html>
<head>
</head>

<body>
<script>
alert( 'Hello, world!' );
</script>
</body>

</html>

3. How to write a comment in JavaScript?


There are two types of comments used in JavaScript:
I. single-line comments
Single line comments start with //.
<script>

var a=10;

var b=20;

var c=a+b;//It adds values of a and b variable

document.write(c);//prints sum of 10 and 20

</script>
II. Multi line comments
Multi-line comments start with /* and end with */.
<script>

/* It is multi line comment.

It will not be displayed */

document.write("example of javascript multiline comment");


</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>

Marks Obtained Dated Sign of Teacher

Process Product Total(25)


Related (10) related(15)

You might also like