You are on page 1of 14

NAME – ANKIT SANGER

ROLL NO.- 029


SUBJECT- WAD ASSIGNMENT

QUESTION1)
Write a program in javascript to calculate
power of number.

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the result of


4*4*4.</p>
<button onclick="myFunction()">Try
it</button>

<p id="demo"></p>

<script>
function myFunction() {

document.getElementById("demo").innerH
TML = Math.pow(4, 3);
}
</script>
</body>
</html>

OUTPUT :-
QUESTION2)
write a program in javascript to arrange
elements of an array.

ANSWER2)

<!DOCTYPE html>
<html>
<body>

<p>Click the button to sort the array.</p>


<button onclick="myFunction()">Try
it</button>

<p id="demo"></p>

<script>
var fruits = ["Banana", "Orange", "Apple",
"Mango"];
document.getElementById("demo").innerH
TML = fruits;

function myFunction() {
fruits.sort();
document.getElementById("demo").innerH
TML = fruits;
}
</script>

</body>
</html>

OUTPUT: -
QUESTION3) WRITE A PROGRAM IN
JAVASCRIPT TO DISPLAY YOUR DETAIL BY
USING OBJECT
AND PROPERTIES OF OBJECT.

ANSWER3)
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>

<p>There are two different ways to access


an object property.</p>

<p>You can use person.property or


person["property"].</p>

<p id="demo"></p>

<script>
// Create an object:
var person = {
firstName: "John",
lastName : "Doe",
id : 5566
};
// Display some data from the object:
document.getElementById("demo").innerH
TML =
person.firstName + " " + person.lastName;
</script>

</body>
</html>

OUTPUT:- JOHN DOE


Q4)
WRITE A PROGRAM TO DESIGN FORM AND
VALIDATE NUMERIC VALUES.

ANS4)

<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
var x =
document.forms["myForm"]["fname"].valu
e;
if (x == "") {
alert("Name must be filled out");
return false;
}
}
</script>
</head>
<body>

<form name="myForm"
action="/action_page.php"
onsubmit="return validateForm()"
method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>

</body>
</html>
QUESTION5) WRITE A PROGRAM TO
DEMONSTRATEUSE OF ALERT BOX,PROMP
BOX.

ANSWER5)
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Alert</h2>
<button onclick="myFunction()">Try
it</button>
<script>
function myFunction() {
alert("I am an alert box!");
}
</script>
</body>
</html>

OUTPUT:-

You might also like