Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (60 loc) · 3.1 KB
/
Copy pathscript.js
File metadata and controls
99 lines (60 loc) · 3.1 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
let message = 'If you are still thinking the answer is no!';
// Log the length of the variable message like `The length of [message] is [length]`
console.log(`The length of ${message} is ${message.length}`);
// Log the character at index 0 of the variable message like `The first character of [message] is [character]`
console.log(`The first character of ${message} is ${message.charAt(0)}`)
// Log the last character of message using length like `The last character of [message] is [character]`
console.log(`The last character of ${message} is ${message.charAt(message.length -1)}`)
// Log the index of word "you" in message
console.log(message.indexOf("you"));
// Log the index of word "still" in message
console.log(message.indexOf("still"));
// Log the index of word "answers" in message
console.log(message.indexOf("answers"));
// Log true or false based on whether the word "answers" exist in message or not
// console.log(message.includes("answers"));
// or
console.log(message.indexOf("answers") !== - 1);
// Log true or false based on whether the word "they" exist in message or not
// console.log(message.includes("they"));
// or
console.log(message.indexOf("they") !== - 1);
// Log true or false based on whether the word "is" exist in message or not
// console.log(message.includes("is"));
// or
console.log(message.indexOf("is") !== - 1);
// Log true or false based on whether the word "Is" exist in message or not
// console.log(message.includes("Is"));
// or
console.log(message.indexOf("Is") !== - 1);
// Check and log whether the word from index 3 to 6 is "you" or not (use slice)
console.log(message.slice(3, 6) === "you");
// Check and log whether the word from index 7 to 8 is "a" or not
console.log(message.slice(7, 8) === "a");
// Check and log whether the last 3 character in message is "no!" or not (you can use -3 in slice)
// console.log(message.endsWith("no!"));
// or
console.log(message.slice(-3) === "no!");
// Check and log whether the last 5 character in message is "no!" or not
console.log(message.slice(-5) === "no!");
// Log the message variable, all in lowecase
console.log(message.toLowerCase());
// Log the message variable, all in uppercase
console.log(message.toUpperCase());
// Replace the word "are" to "can't", store it in a new variable named `newMessage` and log it.
let newMessage = message.replace("are", "can't");
console.log(newMessage);
// Replace the word "still" to "" (empty) using newMessage variable, and re-assign the output to the variable `newMessage` and log it.
newMessage = newMessage.replace("still", "");
// Replace the word "thinking" to "decide" using newMessage variable, and re-assign the output to the variable `newMessage` and log it.
newMessage = newMessage.replace("thinking", "decide");
console.log(newMessage);
// Log all the characters from the message variable (you can user for..of loop on string)
for(char of message){
return char;
}
console.log(return)
// Split all the words in message (split by " " space) and store it in a variable messageArray
let messageArray = message.split(" ");
// Log all the words of messageArray
console.log(messageArray);