|
| 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 | +Practice Problem #2 |
| 32 | +
|
| 33 | +Objective |
| 34 | +Practice using common string methods to manipulate and extract information from strings. |
| 35 | +
|
| 36 | +Instructions: |
| 37 | +You are tasked with processing a single string and |
| 38 | +performing a series of operations using the string methods covered in the lesson. |
| 39 | +Each task corresponds to one or more methods and can be completed independently. |
| 40 | +
|
| 41 | +String to Use: |
| 42 | + let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. "; |
| 43 | +
|
| 44 | +Tasks: |
| 45 | +Complete the following tasks and assign the results to the specified variables. Log each result to the console. |
| 46 | +
|
| 47 | +1. Searching |
| 48 | + - Check if the word "JavaScript" is in the string using includes and assign the result to a variable named hasJavaScript. |
| 49 | + - Find the position of the word "Coding" in the string using indexOf and assign the result to a variable named codingPosition. |
| 50 | + - Check if the string starts with "Welcome" using startsWith and assign the result to a variable named startsWithWelcome. |
| 51 | + - Check if the string ends with "today." using endsWith and assign the result to a variable named endsWithToday. |
| 52 | +
|
| 53 | +2. Transforming |
| 54 | + - Convert the string to all lowercase letters using toLowerCase and assign the result to a variable named lowercaseString. |
| 55 | + - Convert the string to all uppercase letters using toUpperCase and assign the result to a variable named uppercaseString. |
| 56 | + - Remove the extra spaces from the beginning and end of the string using trim and assign the result to a variable named trimmedString. |
| 57 | + - Replace the word "JavaScript" with "coding" using replace and assign the result to a variable named replacedString. |
| 58 | +
|
| 59 | +3. Breaking Apart |
| 60 | + - Split the string into an array of words using split with a space (" ") as the delimiter and assign the result to a variable named wordsArray. |
| 61 | +
|
| 62 | +4. Retrieving |
| 63 | + - Retrieve the first character of the trimmed string using charAt and assign the result to a variable named firstCharacter. |
| 64 | + - Extract the word "Bootcamp" from the string using slice and assign the result to a variable named extractedBootcamp. |
| 65 | +
|
| 66 | +*/ |
| 67 | + |
| 68 | +//Starter Code |
| 69 | +let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. "; |
| 70 | + |
| 71 | +// 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 |
| 76 | + |
| 77 | +// 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 |
| 82 | + |
| 83 | +// 3. Breaking Apart |
| 84 | +let wordsArray; // Your code here |
| 85 | + |
| 86 | +// 4. Retrieving |
| 87 | +let firstCharacter; // Your code here |
| 88 | +let extractedBootcamp; // Your code here |
| 89 | + |
| 90 | +// Log all results |
| 91 | +console.log({ |
| 92 | + hasJavaScript, |
| 93 | + codingPosition, |
| 94 | + startsWithWelcome, |
| 95 | + endsWithToday, |
| 96 | + lowercaseString, |
| 97 | + uppercaseString, |
| 98 | + trimmedString, |
| 99 | + replacedString, |
| 100 | + wordsArray, |
| 101 | + firstCharacter, |
| 102 | + extractedBootcamp, |
| 103 | +}); |
0 commit comments