From 57a747ebb417828f79c7bf503e93b7b605f5fb9c Mon Sep 17 00:00:00 2001 From: Savionrj Date: Mon, 17 Mar 2025 18:36:37 -0500 Subject: [PATCH] common-string-methods --- common-string-methods.js => main.js | 51 +++++++---------------------- 1 file changed, 11 insertions(+), 40 deletions(-) rename common-string-methods.js => main.js (64%) diff --git a/common-string-methods.js b/main.js similarity index 64% rename from common-string-methods.js rename to main.js index f6e2c29..1462919 100644 --- a/common-string-methods.js +++ b/main.js @@ -1,33 +1,4 @@ /* - -Practice Problem #1 - -Activity 1: Searching Strings -Write a program to: -Check if the text "JavaScript" is in the string "Learning JavaScript is fun!" using includes. -Find the position of the word "fun" in the string. - -Activity 2: Transforming Strings -Convert the string " CODE BOOTCAMP " to lowercase and remove all extra whitespace. -Replace "BOOTCAMP" with "JavaScript" in the transformed string. - -Activity 3: Breaking Apart a Sentence -Split the sentence "Coding is fun and educational" into an array of words. - -Activity 4: Retrieving Substrings -Retrieve the first character of "Bootcamp" using charAt. -Extract the word "camp" from "Bootcamp" using slice. - -Advanced Challenge -Write a program to process the following string: -Customer: John Doe -Order: Apple, Banana, Grape -Total: $20.50 -Extract the customer name. -Split the order into an array of items. -Convert the total price to uppercase (e.g., "TOTAL: $20.50"). - - Practice Problem #2 Objective @@ -69,23 +40,23 @@ Complete the following tasks and assign the results to the specified variables. let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. "; // 1. Searching -let hasJavaScript; // Your code here -let codingPosition; // Your code here -let startsWithWelcome; // Your code here -let endsWithToday; // Your code here +let hasJavaScript = inputString.includes("JavaScript"); +let codingPosition = inputString.indexOf("Coding"); +let startsWithWelcome = inputString.startsWith("Welcome"); +let endsWithToday = inputString.endsWith("today."); // 2. Transforming -let lowercaseString; // Your code here -let uppercaseString; // Your code here -let trimmedString; // Your code here -let replacedString; // Your code here +let lowercaseString = inputString.toLowerCase(); +let uppercaseString = inputString.toUpperCase(); +let trimmedString = inputString.trim(); +let replacedString = inputString.replace("JavaScript", "Coding"); // 3. Breaking Apart -let wordsArray; // Your code here +let wordsArray = inputString.split(" "); // 4. Retrieving -let firstCharacter; // Your code here -let extractedBootcamp; // Your code here +let firstCharacter = trimmedString.charAt(0); +let extractedBootcamp = trimmedString.slice(22, 30) // Log all results console.log({