From 90359980f72cf4dd91a856fcb8fe66c2d728f3f5 Mon Sep 17 00:00:00 2001 From: DeepaLaunchCode Date: Fri, 14 Mar 2025 18:50:26 -0500 Subject: [PATCH 1/2] Initial commit - String oprations --- common-string-methods.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/common-string-methods.js b/common-string-methods.js index f6e2c29..1789641 100644 --- a/common-string-methods.js +++ b/common-string-methods.js @@ -69,23 +69,28 @@ 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.trim().startsWith("Welcome"); +let endsWithToday = inputString.trim().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 = trimmedString.split(" "); + // 4. Retrieving -let firstCharacter; // Your code here -let extractedBootcamp; // Your code here +let firstCharacter = trimmedString.charAt(0); +let extractedBootcamp = trimmedString.slice(trimmedString.indexOf("Bootcamp"), trimmedString.indexOf("Bootcamp") + 8); // Log all results console.log({ From b9f23752aa02d10ad5a2255b8e34b8e45fedc229 Mon Sep 17 00:00:00 2001 From: DeepaLaunchCode Date: Fri, 14 Mar 2025 19:11:19 -0500 Subject: [PATCH 2/2] second commit - added lenght module --- common-string-methods.js | 59 ++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/common-string-methods.js b/common-string-methods.js index 1789641..5e07e45 100644 --- a/common-string-methods.js +++ b/common-string-methods.js @@ -65,12 +65,53 @@ Complete the following tasks and assign the results to the specified variables. */ -//Starter Code +//Problem 1 : +let sentence = "Learning JavaScript is fun!"; +let hasJavaScript = sentence.includes("JavaScript"); // Check if "JavaScript" is in the sentence +let funPosition = sentence.indexOf("fun"); // Find the position of "fun" + +// Activity 2: Transforming Strings +let rawString = " CODE BOOTCAMP "; +let trimmedLowerCase = rawString.trim().toLowerCase(); +let transformedString = trimmedLowerCase.replace("bootcamp", "JavaScript"); + +// Activity 3: Breaking Apart a Sentence +let sentenceToSplit = "Coding is fun and educational"; +let wordsArray = sentenceToSplit.split(" "); + +// Activity 4: Retrieving Substrings +let bootcamp = "Bootcamp"; +let firstCharacter = bootcamp.charAt(0); +let extractedCamp = bootcamp.slice(4); + +// Advanced Challenge +let orderDetails = `Customer: John Doe +Order: Apple, Banana, Grape +Total: $20.50`; + +let customerName = orderDetails.split("\n")[0].split(": ")[1]; +let orderItems = orderDetails.split("\n")[1].split(": ")[1].split(", "); +let totalUpperCase = orderDetails.split("\n")[2].toUpperCase(); + +console.log("First program output"); +// Log results +console.log({ + hasJavaScript, + funPosition, + transformedString, + wordsArray, + firstCharacter, + extractedCamp, + customerName, + orderItems, + totalUpperCase, +}); +//Starter Code Problem 2 let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. "; // 1. Searching -let hasJavaScript = inputString.includes("JavaScript"); +let hasJavaScript1 = inputString.includes("JavaScript"); let codingPosition = inputString.indexOf("Coding"); let startsWithWelcome = inputString.trim().startsWith("Welcome"); let endsWithToday = inputString.trim().endsWith("today."); @@ -85,16 +126,18 @@ let replacedString = inputString.replace("JavaScript", "coding"); // 3. Breaking Apart -let wordsArray = trimmedString.split(" "); +let wordsArray1 = trimmedString.split(" "); // 4. Retrieving -let firstCharacter = trimmedString.charAt(0); +let firstCharacter1 = trimmedString.charAt(0); let extractedBootcamp = trimmedString.slice(trimmedString.indexOf("Bootcamp"), trimmedString.indexOf("Bootcamp") + 8); // Log all results -console.log({ - hasJavaScript, +console.log("Second program output"); + + console.log({ + hasJavaScript1, codingPosition, startsWithWelcome, endsWithToday, @@ -102,7 +145,7 @@ console.log({ uppercaseString, trimmedString, replacedString, - wordsArray, - firstCharacter, + wordsArray1, + firstCharacter1, extractedBootcamp, });