COP2500 Lab10
Deliverables:
To complete this assignment you must perfom three tasks --
1.) Show the lab instructor the source code and visible web pages named
"lab10.html".
2.) Email your html documents to your lab instructor before midnight tonight.
Introduction:
The goal of this assignment is to allow you to become familiar
with properties and methods of the String objects. You will be able to change string's appearance and manipulate a string.
Procedures:
PART 1: String formatting methods that mimic the HTML tags
- Open a text editor window.
- Create an html document and name it "lab10.html", then type the following script in it.
<script language="JavaScript">
var str1="String formatting methods!";
document.write("<h3> Part1 </h3>"+"<br>");
document.write("Big: "+str1.big()+"<br>");
document.write("Small: "+str1.small()+"<br>");
document.write("Bold: "+str1.bold()+"<br>");
document.write("Italic: "+str1.italics()+"<br>");
document.write("Fixed: "+str1.fixed()+"<br>");
document.write("Strike: "+str1.strike()+"<br>");
document.write("Fontcolor: "+str1.fontcolor("Red")+"<br>");
document.write("Fontsize: "+str1.fontsize(5)+"<br>");
document.write("Lowercase: "+str1.toLowerCase()+"<br>");
document.write("Uppercase: "+str1.toUpperCase()+"<br>");
document.write("Subscript: "+str1.sub()+"<br>");
document.write("Superscript: "+str1.sup()+"<br>");
document.write("<hr>");
</script>
PART 2:String manipulation method
- Then add the following script at the bottom of the script developed in part1.
var str2="Working with String manipulation method!";
document.write("<h3> Part2 </h3>"+"<br>");
document.write("The first 'm' is at position: "+str2.indexOf("g")+"<br>");
document.write("The last 'm' is at position: "+str2.lastIndexOf("m")+"<br>");
//count number of 't'
var count = 0;
for (i=0;i< str2.length;i++){
if (str2.charAt(i) == 't'){
count++;
}
}
document.write("The number of 't' in this sting 'str2' are: "+count+"<br>")
document.write("The substring from position 8 with length 4 is : "+str2.substr(8,4)+"<br>");
document.write("<hr>");
PART 3: Array of string
- Then add the following script at the bottom of the script developed in part2.
var str3 = new Array(3);
str3[0] = "Java";
str3[1] = "Script";
str3[2] = "Program";
document.write("<h3> Part3 </h3>"+"<br>");
document.write(str3.join(" ") + "<br/>");
document.write(str3.join(",") + "<br />");
document.write(str3.join(".") + "<br/>");
document.write("<hr>");
PART 4: Excercise
- Create a String object containing "Jose lived in San Jose for many years."
- Write a java script to find the index for the second Jose.
- Write a java script to get the substring 'ear' from years.
- using a java method to display the string in a blue, italic font, point size 12, all uppercase.