-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrings.js
56 lines (34 loc) · 1.68 KB
/
Strings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
document.addEventListener('DOMContentLoaded', function () {
// Wait for the HTML to be fully loaded
// Original string
let originalString = "Hello, World!";
// Display original string
document.getElementById("originalString").innerHTML = originalString;
// String method: toUpperCase
let uppercaseString = originalString.toUpperCase();
// Display uppercase string
document.getElementById("uppercaseString").innerHTML = uppercaseString;
let lowercaseString = originalString.toLowerCase();
document.getElementById("lowercaseString").innerHTML = lowercaseString;
let characterAtIndex = originalString.charAt(7);
document.getElementById("characterAtIndex").innerHTML = characterAtIndex;
let indexOfComma = originalString.indexOf(",");
document.getElementById("indexOfComma").innerHTML = indexOfComma;
let slicedString = originalString.slice(7, 12);
document.getElementById("slicedString").innerHTML = slicedString;
let replacedString = originalString.replace("World", "Universe");
document.getElementById("replacedString").innerHTML = replacedString;
let text3 = "I love cats. Cats are very easy to love. Cats are very popular.";
let text4 = text3.replaceAll("Cats","Dogs");
let text5 = text4.replaceAll("cats","dogs");
document.getElementById("rpall").innerHTML = text5;
});
function replacefun() {
let text1 = document.getElementById("repl").innerHTML;
document.getElementById("repl").innerHTML = text1.replace(/RAINY/i,"Sunny");
}
function repall() {
let text2 = document.getElementById("rp").innerHTML;
document.getElementById("rp").innerHTML =
text2.replace(/a/g,"an");
}