0% found this document useful (0 votes)
26 views7 pages

Ajp Practical 1

The document describes an experiment on using JavaScript with HTML. JavaScript can be used for client-side scripting to add interactivity to web pages. The experiment involves writing simple JavaScript code with HTML to evaluate arithmetic expressions and print messages. It will require a computer system with VS Code and Microsoft Edge browser. Several questions and answers are provided as examples of JavaScript concepts like variable declaration, object creation, conditional statements, and arithmetic operations using prompt and alert.

Uploaded by

Hrushikesh Bhoir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Ajp Practical 1

The document describes an experiment on using JavaScript with HTML. JavaScript can be used for client-side scripting to add interactivity to web pages. The experiment involves writing simple JavaScript code with HTML to evaluate arithmetic expressions and print messages. It will require a computer system with VS Code and Microsoft Edge browser. Several questions and answers are provided as examples of JavaScript concepts like variable declaration, object creation, conditional statements, and arithmetic operations using prompt and alert.

Uploaded by

Hrushikesh Bhoir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment No: 01

Title of Experiment Write simple Java Script with HTML for arithmetic expression
evaluation and message printing.

Resources required:

Hardware Software

Computer System 1)VS code


2) Microsoft Edge

Theory
JavaScript is a widely used scripting language originally developed by Netscape for both client-side
and server-side scripting. Client-side JavaScript is used widely and supported well by major browsers
including NN, IE, AOL, MOZILLA, and Opera. We shall present client-side JavaScript for adding
dynamism and interactivity to Web pages and will refer to it simply as JavaScript.

Practical related question:


1. List the application of JavaScript.
Ans: Application of JavaScript are:
 It is used to create interactive websites
 Client-side validation
 Dynamic drop-down menus
 Displaying date and time
 Build small but complete client side programs.
 Displaying popup windows and dialog boxes (like alert dialog box, confirm dialog box and
prompt dialog box)
 Displaying clocks etc.

2. List the features of JavaScript.


Ans: Features of JavaScript are:
 Light Weighted
 Scripting language
 Event handling
 Case Sensitive
 Looping statements

3. How to create an object in JavaScript?


Ans: There are 3 ways to create objects in JavaScript.
• By object literal
• By creating instance of Object directly (using new keyword)
• By using an object constructor (using new keyword)
4. Explain variable in JavaScript.
Ans: Java script did not provide any data types for declaring variables and a variable in java script
can store any type of value. Hence java script is loosely typed language. We can use a variable
directly without declaring it. var keyword are use before variable name to declare any variable.
Syntax: var i;

5. Differentiate between prompt () and alert () methods.


Ans:
 Prompt(): An alert box is one type of popup boxes in JavaScript which is often used to
make sure that information have come through the user. So, the user will have to click
“OK” to proceed when an alert box pops up on the window.
 Alert(): It is also one of the type of popup boxes in JavaScript which is often to take input
a value before entering a page from the user. To proceed after entering an input value in
the prompt, the user will have to click either “OK” or “Cancel”.

6. Write a program to execute the conditional operator(ternary) in JavaScript.


Ans: program:
<!DOCTYPE html>
<html>
<head>
<title>hello</title>
</head>
<body>
<script>
var Marks = 40
if (Marks > 35)
{
document.write("Pass");
}
else
{
document.write("Fail");
} </script>
</body>
</html>
Output:
7. Write a program to perform arithmetic operations by using
a) prompt() //accepts the inputs from user
b) variable assignment // var a=10; var b= 20;
c) function definition
Ans: Program:
<html>
<head>
<title> hello </title>
</head>
<body>
<script>
function msg()
{
var num1 = parseInt (prompt (" Enter a NO "));
var num2 = parseInt (prompt (" Enter a NO "));
result=num1+num2;
window.alert("addition "+result);
}
</script>
<input type="button" value="click" onclick="msg()">
</script>
</body>
</html>
Output:
8. State the use of property getter and setter in JavaScript.
Ans:

Exercise:
Q1) Write a program to print hello world.
Ans: Program:
<!DOCTYPE html>
<html>
<head>
<title>hello</title>
</head>
<body>
<script>
document.write("hello world");
</script>
</body>
</html>

Output:

Q2) write a program to perform arithmetic operation.


Ans: Program:
<html>
<body>
<script type="text/javascript">
var a = 33;
var b = 10;
var c = "Test";
result = a + b;
alert("Addition is "+result);
result = a - b;
alert("Subtraction is "+result);
result = a * b;
alert("multiplication is "+result);
result = a / b;
alert("Division is "+result);
</script>
</body>
</html>

Output:
Conclusion:
We have learnt about how to print message and how to perform arithmetic operation using
alert and prompt.

Marks Obtained Dated Signature of Teacher


Process Related Product Related Total
(15) (35) (50)

You might also like