@@ -65,12 +65,53 @@ Complete the following tasks and assign the results to the specified variables.
65
65
66
66
*/
67
67
68
- //Starter Code
68
+ //Problem 1 :
69
+ let sentence = "Learning JavaScript is fun!" ;
70
+ let hasJavaScript = sentence . includes ( "JavaScript" ) ; // Check if "JavaScript" is in the sentence
71
+ let funPosition = sentence . indexOf ( "fun" ) ; // Find the position of "fun"
72
+
73
+ // Activity 2: Transforming Strings
74
+ let rawString = " CODE BOOTCAMP " ;
75
+ let trimmedLowerCase = rawString . trim ( ) . toLowerCase ( ) ;
76
+ let transformedString = trimmedLowerCase . replace ( "bootcamp" , "JavaScript" ) ;
77
+
78
+ // Activity 3: Breaking Apart a Sentence
79
+ let sentenceToSplit = "Coding is fun and educational" ;
80
+ let wordsArray = sentenceToSplit . split ( " " ) ;
81
+
82
+ // Activity 4: Retrieving Substrings
83
+ let bootcamp = "Bootcamp" ;
84
+ let firstCharacter = bootcamp . charAt ( 0 ) ;
85
+ let extractedCamp = bootcamp . slice ( 4 ) ;
86
+
87
+ // Advanced Challenge
88
+ let orderDetails = `Customer: John Doe
89
+ Order: Apple, Banana, Grape
90
+ Total: $20.50` ;
91
+
92
+ let customerName = orderDetails . split ( "\n" ) [ 0 ] . split ( ": " ) [ 1 ] ;
93
+ let orderItems = orderDetails . split ( "\n" ) [ 1 ] . split ( ": " ) [ 1 ] . split ( ", " ) ;
94
+ let totalUpperCase = orderDetails . split ( "\n" ) [ 2 ] . toUpperCase ( ) ;
95
+
96
+ console . log ( "First program output" ) ;
97
+ // Log results
98
+ console . log ( {
99
+ hasJavaScript,
100
+ funPosition,
101
+ transformedString,
102
+ wordsArray,
103
+ firstCharacter,
104
+ extractedCamp,
105
+ customerName,
106
+ orderItems,
107
+ totalUpperCase,
108
+ } ) ;
109
+ //Starter Code Problem 2
69
110
let inputString = " Welcome to the Coding Bootcamp! Learn JavaScript today. " ;
70
111
71
112
// 1. Searching
72
113
73
- let hasJavaScript = inputString . includes ( "JavaScript" ) ;
114
+ let hasJavaScript1 = inputString . includes ( "JavaScript" ) ;
74
115
let codingPosition = inputString . indexOf ( "Coding" ) ;
75
116
let startsWithWelcome = inputString . trim ( ) . startsWith ( "Welcome" ) ;
76
117
let endsWithToday = inputString . trim ( ) . endsWith ( "today." ) ;
@@ -85,24 +126,26 @@ let replacedString = inputString.replace("JavaScript", "coding");
85
126
86
127
// 3. Breaking Apart
87
128
88
- let wordsArray = trimmedString . split ( " " ) ;
129
+ let wordsArray1 = trimmedString . split ( " " ) ;
89
130
90
131
91
132
// 4. Retrieving
92
- let firstCharacter = trimmedString . charAt ( 0 ) ;
133
+ let firstCharacter1 = trimmedString . charAt ( 0 ) ;
93
134
let extractedBootcamp = trimmedString . slice ( trimmedString . indexOf ( "Bootcamp" ) , trimmedString . indexOf ( "Bootcamp" ) + 8 ) ;
94
135
95
136
// Log all results
96
- console . log ( {
97
- hasJavaScript,
137
+ console . log ( "Second program output" ) ;
138
+
139
+ console . log ( {
140
+ hasJavaScript1,
98
141
codingPosition,
99
142
startsWithWelcome,
100
143
endsWithToday,
101
144
lowercaseString,
102
145
uppercaseString,
103
146
trimmedString,
104
147
replacedString,
105
- wordsArray ,
106
- firstCharacter ,
148
+ wordsArray1 ,
149
+ firstCharacter1 ,
107
150
extractedBootcamp,
108
151
} ) ;
0 commit comments