0% found this document useful (0 votes)
29 views5 pages

CSS - Practical 5

Uploaded by

anasqureshi6556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

CSS - Practical 5

Uploaded by

anasqureshi6556
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CSS- PRACTICAL 5

Name:- Anas Qureshi


Roll No:- 220440
---------------------------------------------------------------------------------------------------------------------------
Q1. Write a program to create a string using different methods and finding the length of string.
Code: -
<html>
<head>
<title>Anas-220440</title>
<script>
document.write("<h3>Anas Qureshi-2204</h3><hr>")
var str1="HI Anas!";
var n1=str1.length;
var str2=new String("Let's Learn CSS!");
var n2=str2.length;
var txt1="JAVA";
var txt2="SCRIPT";
var txt3=txt1.concat(" ",txt2);
var n3=txt3.length;
document.write(str1 + "<br>");
document.write("<p>Length :" + n1 + "</p>");
document.write(str2 + "<br>");
document.write("<p>Length :" + n2 + "</p>");
document.write(txt3 + "<br>");
document.write("<p>Length :" + n3 + "</p>");
</script>
</head>
<body>
</body>
</html>
Output: -

Q2. Write a program to find the index of particular String using different parameters.
Code: -
<html>
<head>
<title>Anas-220440</title>
</head>
<body>
<script>
var str1="Hey Anas!";
document.write("<br> FIRST STRING : " + str1 + "<br>");
var n1=str1.search("e");
document.write("<br>'e' FOUND AT LOCATION " + n1 + "<br>");
var n2=str1.indexOf("A");
document.write("<br>'A' FOUND AT LOCATION " + n2 + "<br>");
var n3=str1.lastIndexOf("HELLO");
document.write("<br>'HELLO' FOUND AT LOCATION " + n3 + "<br>");
</script>
</body>
</html>
Output: -

Q3. Write a program for extracting the String using different parameters.
Code: -
<html>
<head>
<title>Anas-220440</title>
</head>
<body>
<script>
var str1="JavaScript is an Interpreted language.";
document.write("<h3>Anas Qureshi - 220440</h3><hr>");
document.write("SUBSTRING: " + str1.substr(0,10));
document.write("<br> SUBSTRING: " + str1.substr(16));
document.write("<br> SUBSTRING: " + str1.substring(33,42));
document.write("<br> SUBSTRING: " + str1.substring(33));
document.write("<br> SUBSTRING: " + str1.substring(32,0));
</script>
</body>
</html>
Output: -

Q4. Write a program for replacing and converting the String to uppercase and Lowercase using
different methods and parameters.
Code: -
<html>
<head>
<title>Anas Qureshi-220440</title>
</head>
<body>
<script>
var str1="Anas Qureshi";
document.write("ORIGINAL STRING: " + str1 );
document.write("<br> UPPERCASE: " + str1.toUpperCase());
document.write("<br> LOWERCASE: " + str1.toLowerCase() + "</p>");
</script>
</body>
</html>
Output: -

Q5. Write a program to concatenate two strings.


Code: -
<html>
<head>
<title>Anas Qureshi-220440</title>
</head>
<body>
<script>
var str1=new String("Anas");
var str2=new String("Qureshi");
var str3=new String(".");
var str4=str1+str2;
var str5=str2.concat(" ",str3);
var str6=str1.concat(" ",str2," ",str3);
document.write("str4 : " + str4);
document.write("<br>str5 : " + str5);
document.write("<br>str6 : " + str6);
</script>
</body>
</html>
Output: -

Q6. Write a program to trim the whitespace, find the character code as well as the character at
the specific index.
Code: -
<html>
<head>
<title>Anas Qureshi-220440</title>
</head>
<body>
<script>
var str1="Hello World ";
document.write("Unicode of H " + str1.charCodeAt() );
document.write("<br> Unicode of Space " + str1.charCodeAt(5));
var res=String.fromCharCode(65,78,65,83);
document.write("<br> String from Unicode: " + res);
var str2=" Hello World ";
document.write("<br>String Trim: " + str2.trim() );
</script>
</body>
</html>
Output: -
Q7. Write a program to convert the string to number using different function.
Code: -
<html>
<head>
<title>Anas Qureshi-220440</title>
</head>
<body>
<script>
function strToNumber()
{
var x1=true;
var x2=false;
var x3=new Date();
var x4=parseInt("9 years");
var x5=parseInt("I'm 10");
var x6=parseFloat("10.203");
var x7=parseFloat("5 Years");
var n=Number(x1) + "<br>" + Number(x2) + "<br>" + Number(x3)
+ "<br>" + x4 + "<br>" + x5 + "<br>" + x6 + "<br>" + x7;
document.write(n);
}
strToNumber();
</script>
</body>
</html>
Output: -

You might also like