You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: common-string-methods.js
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -69,23 +69,23 @@ Complete the following tasks and assign the results to the specified variables.
69
69
letinputString=" Welcome to the Coding Bootcamp! Learn JavaScript today. ";
70
70
71
71
// 1. Searching
72
-
lethasJavaScript;// Your code here
73
-
letcodingPosition;// Your code here
74
-
letstartsWithWelcome;// Your code here
75
-
letendsWithToday;// Your code here
72
+
lethasJavaScript=inputString.includes("JavaScript");// Check if "JavaScript" is in the string
73
+
letcodingPosition=inputString.indexOf("Coding");// Find the position of the word "Coding"
74
+
letstartsWithWelcome=inputString.startsWith("Welcome");// Check if the string starts with "Welcome"
75
+
letendsWithToday=inputString.endsWith("today.");// Check if the string ends with "today."
76
76
77
77
// 2. Transforming
78
-
letlowercaseString;// Your code here
79
-
letuppercaseString;// Your code here
80
-
lettrimmedString;// Your code here
81
-
letreplacedString;// Your code here
78
+
letlowercaseString=inputString.toLowerCase();// Convert the string to all lowercase letters
79
+
letuppercaseString=inputString.toUpperCase();// Convert the string to all uppercase letters
80
+
lettrimmedString=inputString.trim();// Remove extra spaces from the beginning and end of the string
81
+
letreplacedString=trimmedString.replace("JavaScript","coding");// Replace "JavaScript" with "coding"
82
82
83
83
// 3. Breaking Apart
84
-
letwordsArray;// Your code here
84
+
letwordsArray=trimmedString.split(" ");// Split the string into an array of words
85
85
86
86
// 4. Retrieving
87
-
letfirstCharacter;// Your code here
88
-
letextractedBootcamp;// Your code here
87
+
letfirstCharacter=trimmedString.charAt(0);// Retrieve the first character of the trimmed string
88
+
letextractedBootcamp=trimmedString.slice(trimmedString.indexOf("Bootcamp"),trimmedString.indexOf("Bootcamp")+"Bootcamp".length);// Extract the word "Bootcamp" from the string from the index of the first letter through the length of the word.
0 commit comments