Web 5 69
Web 5 69
5
Aim: Write javascript code for
A] Demonstrating different javascript objects such as string,regexpath,date.
1] Regular expression demonstration.
INPUT:
<html>
<body>
<p>regular expression</p>
<button on click=”myfunction()”>try it</button>
<script>
Function myfunction(){
Varstr=”all these are not possible using html”
Varn=str.search(/possible/i);
Document.write(“<br>”+n+”<br>”);
Var res=str.replace(/possible/I,”possible”);
Document.write(“<br>”+res+”<br>”);
Varpatt=/e/;
Document.write(“<br>”+patt.test(str)+”<br>”);}
</script>
</body>
</html>
OUTPUT:
18
ROLL NO.:69
All these are not possible using html!
true
2] String demonstration.
INPUT:
<html>
<body>
<script>
Var str1=”hey diddle diddle,the cat and the fiddle,the cow jumped over the
moon,”
Var str2=”the little dog laughed to see such fun,and the dish ran away with
the spoon!”;
Document.write(str1+”<br>”+str2+”<br>”);
Var sln=str1.length
Document.write(“<br>”+”length if string is”+sln+”<br>”);
Var x=’it\’s alright’;
Var y=”we are the so-called\”vikings\”from the north.”
Document.write(“<br>”+x+”<br>”);
Document.write(“<br>”+y+”<br>”);
</script>
</body>
</html>
OUTPUT:
Hey diddle diddle,the cat and the fiddle,the cow jumped over the moon,
ROLL NO.:69
The little dog laughed to see such fun,and the dish ran away with the spoon!
Length if string is70
It’s alright
We are the so-called”vikings”from the north.
}
Else{
Alert(“ok”);
}
ROLL NO.:69
Else{
Alert(“cancel”);
}
}
</script>
</body>
</html>
OUTPUT:
ROLL NO.:69