Practical No 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Practical No.

Aim: Develop JavaScript to implement functions.

<html>

<body>

<script type="text/javascript"> function sayHellojavascript() {

alert("Hello javascript");

</script>

</body>

</html>

<html>

<body>

<script type="text/javascript">

function distance(x1, y1, x2, y2) {

var dx=x2-x1;

var dy=y2-y1;

return Math.sqrt(dx*dx + dy*dy);

document.write(distance(10, 20, 30, 40))

</script>

</body>

</html>
<html>

<head>

<title> scope</title>

<script>

var global="Global Variable <hr>";

function init()

document.write(global);

show();

function show()

var local="Local Variable <hr>";

document.write(local);

document.write(global)

</script>

</head>

<body>

<script>

init();

</script>

</body>

</html>
<html>

<head>

<title> Calling Function without Arguments </title>

<script type="text/javascript">

var x=10;

function show(){

var item="pen";

document.write("The cost of the "+ item +" is "+ x);

</script>

</head>

<body>

<script type="text/javascript">

show();

</script>

</body>

</html>

<html>

<head>

<title> Calling Function with Arguments </title>

<script type="text/javascript">

function add(x, y) {
resultx+y; document.write("addition is: " + result);

document.write("<br/>");

</script>

</head>

<body>

<script type="text/javascript">

add(10, 10);

add(23, 12);

</script>

</body>

</html>

<html>

<head>

<title> Calling Function from HTML </title>

<script type="text/javascript">

function welcome()

alert('welcome dear..')

function goodbye()

alert('Bye bye..')

</script>

</head>

<body onload="welcome()" onunload="goodbye()"> </body>

</html>
<html>

<head>

<title> scope </title>

<script>

function Logon(){

var userID;

var password;

var valid;

userID = prompt('Enter user ID','');

password=prompt('Enter password','');

valid=ValidateLogon(userID, password);

if (valid === true){

alert('Valid Logon');

else{

alert('Invalid Logon');

}function ValidateLogon(id, pwd) {

var ReturnValue;

if (id === '111' && pwd === 'aaa'){

ReturnValue = true;

} else{

ReturnValue=false;

return ReturnValue;

</script>

</head>

<body onload="Logon()"></body>

</html>
<html>

<head>

<title>Javascript Return statement</title>

</head>

<body>

<script type="text/javascript">

function areaRect(L,B){

var area=L*B;

return area;

x=areaRect(6,8);

document.write(x);

</script>

</body> </html>

You might also like