Skip to content

Commit 57a747e

Browse files
committed
common-string-methods
1 parent ce4948b commit 57a747e

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

common-string-methods.js renamed to main.js

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
11
/*
2-
3-
Practice Problem #1
4-
5-
Activity 1: Searching Strings
6-
Write a program to:
7-
Check if the text "JavaScript" is in the string "Learning JavaScript is fun!" using includes.
8-
Find the position of the word "fun" in the string.
9-
10-
Activity 2: Transforming Strings
11-
Convert the string " CODE BOOTCAMP " to lowercase and remove all extra whitespace.
12-
Replace "BOOTCAMP" with "JavaScript" in the transformed string.
13-
14-
Activity 3: Breaking Apart a Sentence
15-
Split the sentence "Coding is fun and educational" into an array of words.
16-
17-
Activity 4: Retrieving Substrings
18-
Retrieve the first character of "Bootcamp" using charAt.
19-
Extract the word "camp" from "Bootcamp" using slice.
20-
21-
Advanced Challenge
22-
Write a program to process the following string:
23-
Customer: John Doe
24-
Order: Apple, Banana, Grape
25-
Total: $20.50
26-
Extract the customer name.
27-
Split the order into an array of items.
28-
Convert the total price to uppercase (e.g., "TOTAL: $20.50").
29-
30-
312
Practice Problem #2
323
334
Objective
@@ -69,23 +40,23 @@ Complete the following tasks and assign the results to the specified variables.
6940
let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. ";
7041

7142
// 1. Searching
72-
let hasJavaScript; // Your code here
73-
let codingPosition; // Your code here
74-
let startsWithWelcome; // Your code here
75-
let endsWithToday; // Your code here
43+
let hasJavaScript = inputString.includes("JavaScript");
44+
let codingPosition = inputString.indexOf("Coding");
45+
let startsWithWelcome = inputString.startsWith("Welcome");
46+
let endsWithToday = inputString.endsWith("today.");
7647

7748
// 2. Transforming
78-
let lowercaseString; // Your code here
79-
let uppercaseString; // Your code here
80-
let trimmedString; // Your code here
81-
let replacedString; // Your code here
49+
let lowercaseString = inputString.toLowerCase();
50+
let uppercaseString = inputString.toUpperCase();
51+
let trimmedString = inputString.trim();
52+
let replacedString = inputString.replace("JavaScript", "Coding");
8253

8354
// 3. Breaking Apart
84-
let wordsArray; // Your code here
55+
let wordsArray = inputString.split(" ");
8556

8657
// 4. Retrieving
87-
let firstCharacter; // Your code here
88-
let extractedBootcamp; // Your code here
58+
let firstCharacter = trimmedString.charAt(0);
59+
let extractedBootcamp = trimmedString.slice(22, 30)
8960

9061
// Log all results
9162
console.log({

0 commit comments

Comments
 (0)