Skip to content

Commit b9f2375

Browse files
second commit - added lenght module
1 parent 9035998 commit b9f2375

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

common-string-methods.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,53 @@ Complete the following tasks and assign the results to the specified variables.
6565
6666
*/
6767

68-
//Starter Code
68+
//Problem 1 :
69+
let sentence = "Learning JavaScript is fun!";
70+
let hasJavaScript = sentence.includes("JavaScript"); // Check if "JavaScript" is in the sentence
71+
let funPosition = sentence.indexOf("fun"); // Find the position of "fun"
72+
73+
// Activity 2: Transforming Strings
74+
let rawString = " CODE BOOTCAMP ";
75+
let trimmedLowerCase = rawString.trim().toLowerCase();
76+
let transformedString = trimmedLowerCase.replace("bootcamp", "JavaScript");
77+
78+
// Activity 3: Breaking Apart a Sentence
79+
let sentenceToSplit = "Coding is fun and educational";
80+
let wordsArray = sentenceToSplit.split(" ");
81+
82+
// Activity 4: Retrieving Substrings
83+
let bootcamp = "Bootcamp";
84+
let firstCharacter = bootcamp.charAt(0);
85+
let extractedCamp = bootcamp.slice(4);
86+
87+
// Advanced Challenge
88+
let orderDetails = `Customer: John Doe
89+
Order: Apple, Banana, Grape
90+
Total: $20.50`;
91+
92+
let customerName = orderDetails.split("\n")[0].split(": ")[1];
93+
let orderItems = orderDetails.split("\n")[1].split(": ")[1].split(", ");
94+
let totalUpperCase = orderDetails.split("\n")[2].toUpperCase();
95+
96+
console.log("First program output");
97+
// Log results
98+
console.log({
99+
hasJavaScript,
100+
funPosition,
101+
transformedString,
102+
wordsArray,
103+
firstCharacter,
104+
extractedCamp,
105+
customerName,
106+
orderItems,
107+
totalUpperCase,
108+
});
109+
//Starter Code Problem 2
69110
let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. ";
70111

71112
// 1. Searching
72113

73-
let hasJavaScript = inputString.includes("JavaScript");
114+
let hasJavaScript1 = inputString.includes("JavaScript");
74115
let codingPosition = inputString.indexOf("Coding");
75116
let startsWithWelcome = inputString.trim().startsWith("Welcome");
76117
let endsWithToday = inputString.trim().endsWith("today.");
@@ -85,24 +126,26 @@ let replacedString = inputString.replace("JavaScript", "coding");
85126

86127
// 3. Breaking Apart
87128

88-
let wordsArray = trimmedString.split(" ");
129+
let wordsArray1 = trimmedString.split(" ");
89130

90131

91132
// 4. Retrieving
92-
let firstCharacter = trimmedString.charAt(0);
133+
let firstCharacter1 = trimmedString.charAt(0);
93134
let extractedBootcamp = trimmedString.slice(trimmedString.indexOf("Bootcamp"), trimmedString.indexOf("Bootcamp") + 8);
94135

95136
// Log all results
96-
console.log({
97-
hasJavaScript,
137+
console.log("Second program output");
138+
139+
console.log({
140+
hasJavaScript1,
98141
codingPosition,
99142
startsWithWelcome,
100143
endsWithToday,
101144
lowercaseString,
102145
uppercaseString,
103146
trimmedString,
104147
replacedString,
105-
wordsArray,
106-
firstCharacter,
148+
wordsArray1,
149+
firstCharacter1,
107150
extractedBootcamp,
108151
});

0 commit comments

Comments
 (0)