|
1 | 1 | /*
|
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 |
| -
|
31 | 2 | Practice Problem #2
|
32 | 3 |
|
33 | 4 | Objective
|
@@ -69,23 +40,23 @@ Complete the following tasks and assign the results to the specified variables.
|
69 | 40 | let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. ";
|
70 | 41 |
|
71 | 42 | // 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."); |
76 | 47 |
|
77 | 48 | // 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"); |
82 | 53 |
|
83 | 54 | // 3. Breaking Apart
|
84 |
| -let wordsArray; // Your code here |
| 55 | +let wordsArray = inputString.split(" "); |
85 | 56 |
|
86 | 57 | // 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) |
89 | 60 |
|
90 | 61 | // Log all results
|
91 | 62 | console.log({
|
|
0 commit comments