Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset=“utf-8”>
- <title> Assignment 2 </title>
- </head>
- <body>
- <script type="text/javascript">
- <!--
- text = "now is the time for all good people to come to the aid of their country";
- document.write("Text: "+text+"<br><br>");
- // Each Letter Capitalized
- function capitalize(str) {
- return str.replace(/\w\S*/g, function(txt) {
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
- }
- x = capitalize(text);
- document.write(x+"<br>");
- // Each Last Letter Capitalized
- function capitalize2(str) {
- return str.replace(/\w\S*/g, function(txt) {
- return txt.substr(0,txt.length-1).toLowerCase() + txt.substr(txt.length-1).toUpperCase(); });
- }
- x = capitalize2(text);
- document.write(x+"<br>");
- // Capitalize Letters Without UpperCase
- for(i=0;i<text.length;i++)
- {
- if ( text.charCodeAt(i) == 32) {
- document.write(" ");
- }
- else {
- a = String.fromCharCode(text.charCodeAt(i)-32)
- document.write(a);
- }
- }
- document.write("<br>");
- // first i
- index1 = text.indexOf("i");
- document.write(+index1+ "th poisition holds the first 'i' <br>");
- // last i
- index2 = text.lastIndexOf("i");
- document.write(+index2+ "th poisition holds the last 'i' <br>");
- // How many letters
- letter1 = text.charAt(8);
- document.write("8th letter is '"+letter1+"'<br>");
- // Length
- lenght1 = text.length;
- document.write("There are "+lenght1+" letters in the text<br>");
- <!--
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement