4. (C) Design a web page demonstrating different Core JavaScript references (Array, Boolean, Date, Function, Math, Number, Object, String, regExp).

4. (C) Design a web page demonstrating different Core JavaScript references (Array, Boolean, Date, Function, Math, Number, Object, String, regExp).

Array:
<html>
<head>
<title>Array object Demo</title>
<script>
var names=["ajay","vijay","sujay"];
document.write("Array length is: "+names.length+"<br><br>");
var c=names.join("*");
document.write(c+"<br><br>");
names.push("aviraj");
document.write("After insert: "+names.toString()+"<br><br>");
names.pop();
document.write("After delete: "+names.toString()+"<br><br>");
names.sort();
document.write("After sort: "+names.toString()+"<br><br>");
names.reverse();
document.write("After reverse: "+names.toString()+"<br><br>");
</script>
</head>
<body>
</body>
</html>

Boolean:
<html>
<head>
<title>Boolean object demo</title>
<script>
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:
<html>
<head>
<title> Date object demo </title>
<script>
var currentDate =new Date();
document.write(currentDate+"<br>");
document.write("Date is:");
document.write(currentDate.getMonth()+"/"+currentDate.getDate()+"/"+currentDate.getFullYear()+"<br>");
document.write("Time is:");
document.write(currentDate.getHours()+":"+currentDate.getMinutes()+":"+currentDate.getSeconds());
</script>
<head>
<body>
</body>
</html

Function:
<html>
<head>
<title> function object demo</title>
<script>
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:
<html>
<head>
<title>math object</title>
<script>
document.write("Random number: " +Math.random()+"<br>");
document.write("Minimum number: "+Math.min(10,22,55,101,02,33,-88)+"<br>");
document.write("Maximum number: "+Math.max(22,888,99,55,22,11,20)+"<br>");
document.write("Round(99.8): "+Math.round(99.8)+"<br>");
document.write("Ceil(5.5): "+Math.ceil(5.5)+"<br>");
document.write("Floor(5.5): "+Math.floor(5.5)+"<br>");
document.write("Square root of 9: "+Math.sqrt(9)+"<br>");
document.write("Square root of 64: "+Math.sqrt(64)+"<br>");
document.write("5 raise to 3: "+Math.pow(5,3)+"<br>");
</script>
</head>
<body>
</body>
</html>

Number:
<html>
<head>
<title>Number object Demo</title>
<style>
#one{
float: left;
width: 125px;
text-align:left;
margin: 2px 50px;
display: inline;
}
#two{
float: left;
text-align: left;
margin: 2px 100px;
display: inline;
}
</style>
</head>
<body>
<div id="one">
<p>toString Method<p>
<p id="toString"></p>
<p>toExponential Method<p>
<p id="toExponential"></p>
<p><p>
<p id=""></p>
<p>toFixed Method<p>
<p id="toFixed"></p>
<p>toPrecision Method</p>
<p id="toPrecision"></p>
<p>valueOf Method</p>
<p id="valueOf"></p>
</div>
<div id="two">
<p>Number Method</p>
<p id="Number"></p>
<p>parseInt Method</p>
<p id="parseInt"></p>
<p>parseFloat Method</p>
<p id="parseFloat"></p>
<p>MAX_VALUE Method</p>
<p id="MAX_VALUE"></p>
</div>
<script>
var x = 123;
document.getElementById("toString").innerHTML =
x.toString() + "<br>" +
(123).toString() + "<br>" +
(100 + 23).toString();
var x = 9.656;
document.getElementById("toExponential").innerHTML =
x.toExponential() + "<br>" +
x.toExponential(2) + "<br>" +
x.toExponential(4) + "<br>" +
x.toExponential(6);
var x = 9.656;
document.getElementById("toFixed").innerHTML =
x.toFixed(0) + "<br>" +
x.toFixed(2) + "<br>" +
x.toFixed(4) + "<br>" +
x.toFixed(6);
var x = 9.656;
document.getElementById("toPrecision").innerHTML =
x.toPrecision() + "<br>" + x.toPrecision(2) + "<br>" +
x.toPrecision(4) + "<br>" +x.toPrecision(6);
var x = 123;
document.getElementById("valueOf").innerHTML =
x.valueOf() + "<br>" +
(123).valueOf() + "<br>" +
(100 + 23).valueOf();
document.getElementById("Number").innerHTML =
Number(true) + "<br>" +
Number(false) + "<br>" +
Number(new Date()) + "<br>" +
Number(" 10") + "<br>" +
Number("10 ") + "<br>" +
Number("10 6");
document.getElementById("parseInt").innerHTML =
parseInt("10") + "<br>" +
parseInt("10.33") + "<br>" +
parseInt("10 6") + "<br>" +
parseInt("10 years") + "<br>" +
parseInt("years 10");
document.getElementById("parseFloat").innerHTML =
parseFloat("10") + "<br>" + parseFloat("10.33") + "<br>" +
parseFloat("10 6") + "<br>" + parseFloat("10 years") + "<br>" +
parseFloat("years 10");
document.getElementById("MAX_VALUE").innerHTML = Number.MAX_VALUE;
</script></body></html>

String:
<html>
<head>
<title>String object Demo</title>
<script>
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write(txt.length+"<br><br>");
var x = 'It\'s alright';
var y = "We are the so-called \"Vikings\" from the north.";
document.write(x + "<br>" + y+"<br><br>");
var str = "Please locate where 'locate' occurs!";
var pos = str.indexOf("locate");
document.write(pos+"<br><br>");
var str = "Please locate where 'locate' occurs!";
var pos = str.lastIndexOf("locate");
document.write(pos+"<br><br>");
var str = "Please locate where 'locate' occurs!";
var pos = str.search("locate");
document.write(pos+"<br><br>");
var str = "Apple, Banana, Kiwi";
var res = str.slice(7, 13);
document.write(res+"<br><br>");
var str = "Apple, Banana, Kiwi";
var res = str.substring(7, 13);
document.write(res+"<br><br>");
var str = "Apple, Banana, Kiwi";
var res = str.substr(7, 6);
document.write(res+"<br><br>");
var str = "Please visit Microsoft!";
var n = str.replace("Microsoft", "W3Schools");
document.write(n+"<br><br>");
var text1 = "Hello World!";
var text2 = text1.toUpperCase();
document.write(text2+"<br><br>");
var text1 = "Hello World!";
var text2 = text1.toLowerCase();
document.write(text2+"<br><br>");
var text1 = "Hello";
var text2 = "World";
text3 = text1.concat(" ", text2);
document.write(text3+"<br><br>");
var str = "HELLO WORLD";
document.write(str.charAt(0));
document.write("<br><br>")
var str = "HELLO WORLD";
document.write(str.charCodeAt(0));
document.write("<br><br>")
var str = "A,J,I,T,C,H,A,V,A,N";
var arr = str.split(",");
document.write(arr[8 ]);
</script>
</head>
<body>
</body>
</html>

regExp:
<html>
<head>
<title>RegExp object Demo</title>
<script language="javascript">
var str = "Visit W3Schools!";
var n = str.search(/w3Schools/i);
document.write(n+"<br><br>");
var str = "Visit Microsoft!";
var res = str.replace(/microsoft/i, "W3Schools");
document.write(res+"<br><br>");
text = "The best things in life are free!";
document.write(/e/.test(text)+"<br><br>");
text = "The best things in life are free!";
document.write(/e/.exec(text)+"<br><br>");
</script>
</head>
<body>
</body>
</html>
4. (C) Design a web page demonstrating different Core JavaScript references (Array, Boolean, Date, Function, Math, Number, Object, String, regExp). 4. (C) Design a web page demonstrating different Core JavaScript references (Array, Boolean, Date, Function, Math, Number, Object, String, regExp). Reviewed by admin on December 24, 2019 Rating: 5

No comments:

Powered by Blogger.