FY B.sc IT Practical 4(C) : Design a web page demonstrating different Core JavaScript references (Array, Boolean, Date, Function, Math, Number, Object, String, regExp).
Array object code:
<!DOCTYPE html>
<html>
<head>
<title>Array object Demo</title>
<script language="javascript">
var
cars=["Saab","Volvo","BMW"];
document.write("Array length
is: "+cars.length+"<br>");
document.write(cars.join["*"]);
cars.push("Opel");
document.write("After
insert: "+cars.toString());
cars.pop();
document.write("After
delete: "+cars.toString());
cars.sort();
document.write("After sort:
"+cars.toString());
cars.reverse();
document.write("After
reverse: "+cars.toString());
</script>
</head>
<body>
</body>
</html>
Boolean object code:
<!DOCTYPE html>
<html>
<head>
<title>Boolean object demo</title>
<script language="javascript">
function myFunction()
{
document.getElementById("demo").innerHTML
= Boolean(10 > 9);
}
</script>
</head>
<body>
<p>Display the value of Boolean(10 > 9):</p>
<button onclick="myFunction()">Try
it</button>
<p id="demo"></p>
</body>
</html>
Date object code:
<!DOCTYPE html>
<html>
<head>
<title> Date object demo </title>
<script language="javascript">
var currentDate =new Date();
document.write("Date
is:");
document.write(currentDate.getMonth()+"/"+currentDate.getDate()+"/"+currentDate.getFullYear()+"<br>");
document.write("Time is:");
document.write(currentDate.getHours()+":"+currentDate.getMinutes()+":"+currentDate.getSecond());
</script>
<head>
<body>
</body>
</html>
Function object code:
<!DOCTYPE html>
<html>
<head>
<title> function object demo</title>
<script language="javascript">
addBraces=new
Function("s","return'['+s+']'");
document.write(addBraces("this"));
document.write(addBraces("is"));
document.write(addBraces("a"));
document.write(addBraces("test"));
</script>
</head>
<body>
</body>
</html>
Math object code:
<!DOCTYPE html>
<html>
<head>
<title>math object</title>
<script language="javascript">
document.write("Random
number: " +Math.random(3)+"<br>");
document.write("Minimum
number: "+Math.min(150,0,-29,60)+"<br>");
document.write("Maximum
number: "+Math.max(600,120,129,89)+"<br>");
document.write("Round(47.6):
"+Math.round(47.6)+"<br>");
document.write("Ceil(4.4):
"+Math.ceil(4.4)+"<br>");
document.write("Floor(4.7):
"+Math.floor(4.7)+"<br>");
document.write("Square root
of 2: "+Math.SQRT2+"<br>");
document.write("Square root
of 1/2: "+Math.SQRT1_2+"<br>");
document.write("2 raise to
3: "+Math.pow(2,3)+"<br>");
</script>
</head>
<body>
</body>
</html>
Number object demo:
<!DOCTYPE html>
<html>
<head>
<title>Number object Demo</title>
<script language="javascript">
document.write("Maximum
value: "+Number.MAX_VALUE;);
document.write("Minimum
value: "+Number.MIN_VALUE;);
var num1 = 5.56789;
document.write(num1.toFixed(2));
var num2 = 13.3714;
document.write(num2.toPrecision(2));
document.write(num1.toString());
</script>
</head>
<body>
</body>
</html>
Object object code:
<!DOCTYPE html>
<html>
<head>
<title> object demo </title>
<script language="javascript">
myobj1=new Object(123);
document.write(myobj1.toString()+"<br>");
myobj2=new Object("hello
world");
document.write(myobj2.valueOf());
</script>
</head>
<body>
</body>
</html>
String object demo:
<!DOCTYPE html>
<html>
<head>
<title>String object Demo</title>
<script language="javascript">
var txt =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write(txt.length);
var x = 'It\'s alright';
var y = "We are the
so-called \"Vikings\" from the north.";
document.write(x +
"<br>" + y);
var str = "Please locate
where 'locate' occurs!";
var pos =
str.indexOf("locate");
document.write(pos);
var str = "Please locate
where 'locate' occurs!";
var pos =
str.lastIndexOf("locate");
document.write(pos);
var str = "Please locate
where 'locate' occurs!";
var pos =
str.search("locate");
document.write(pos);
var str = "Apple, Banana,
Kiwi";
var res = str.slice(7, 13);
document.write(res);
var str = "Apple, Banana,
Kiwi";
var res = str.substring(7, 13);
document.write(res);
var str = "Apple, Banana,
Kiwi";
var res = str.substr(7, 6);
document.write(res);
var str = "Please visit
Microsoft!";
var n =
str.replace("Microsoft", "W3Schools");
document.write(n);
var text1 = "Hello
World!";
var text2 = text1.toUpperCase();
document.write(text2);
var text1 = "Hello
World!";
var text2 = text1.toLowerCase();
document.write(text2);
var text1 = "Hello";
var text2 = "World";
text3 = text1.concat("
", text2);
document.write(text3);
var str = "HELLO
WORLD";
documet.write(str.charAt(0));
var str = "HELLO
WORLD";
documet.write(str.charCodeAt(0));
var txt = "a,b,c,d,e";
var arr=txt.split(" ");
document.write(arr[0]+"
"+arr[2]);
</script>
</head>
<body>
</body>
</html>
RegEx object demo:
<!DOCTYPE html>
<html>
<head>
<title>RegExp object Demo</title>
<script language="javascript">
var str = "Visit
W3Schools!";
var n = str.search(/w3Schools/i);
document.write(n);
var str = "Visit
Microsoft!";
var res =
str.replace(/microsoft/i, "W3Schools");
document.write(res);
text = "The best things in life are
free!";
document.write(/e/.test(text));
text = "The best things in life are
free!";
document.write(/e/.exec(text));
</script>
</head>
<body>
</body>
</html>
Comments
Post a Comment