-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.html
More file actions
50 lines (39 loc) · 1.16 KB
/
Copy pathstrings.html
File metadata and controls
50 lines (39 loc) · 1.16 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Strings</title>
<script>
let input = "jenny@wickedlysmart.com";
for (let i = 0; i < input.length; i++) {
if (input.charAt(i) === "@") {
console.log(`There's an @ sign at index ${i}`);
}
}
let phrase = "the cat in the hat";
let index = phrase.indexOf("cat");
console.log(`There's a cat sitting at index ${index}`);
index = phrase.indexOf("the", 5);
console.log(`There's a the sitting at index ${index}`);
index = phrase.indexOf("dog");
console.log(`There's a dog sitting at index ${index}`);
let data = "name|phone|address";
let val = data.substring(5, 10);
console.log(`Substring is ${val}`);
val = data.substring(5);
console.log(`Substring is now ${val}`);
let vals = data.split("|");
console.log("Split array is ", vals);
let phone = "(201)555-1212";
phone = phone.replace("2", "9");
console.log(`Updated phone: ${phone}`);
phone = phone.replaceAll("2", "9");
console.log(`Updated phone: ${phone}`);
phone = "(201)555-1212";
console.log(`Is area code "201"? ${phone.includes("(201)")}`);
console.log(`Is area code "206"? ${phone.includes("(206)")}`);
</script>
</head>
<body>
</body>
</html>