@@ -46,7 +46,7 @@ let index1 = 0;
4646let index2 = 2;
4747
4848Expected Output:
49- codePointDifference: 16 // 'C' = 67, 't' = 116, |67 - 116| = 16
49+ codePointDifference: 49 // 'C' = 67, 't' = 116, |67 - 116| = 49
5050
5151
5252
@@ -84,25 +84,58 @@ Assign the result to a variable named swappedString.
8484*/
8585
8686//Starter Code
87- // Task 1
88- let inputString1 = "Code" ;
89- let firstCodePoint = inputString1 . charCodeAt ( 0 ) ;
90- let thirdCodePoint = inputString1 . charCodeAt ( 2 ) ;
91-
92- // Task 2
93- let wordFromCodePoints = String . fromCharCode ( 72 , 101 , 108 , 108 ) ;
94-
95- // Task 3
96- let inputString2 = "Launch" ;
97- let swappedString = String . fromCharCode ( inputString2 . charCodeAt ( inputString2 . length - 1 ) ) +
98- inputString2 . slice ( 1 , - 1 ) +
99- String . fromCharCode ( inputString2 . charCodeAt ( 0 ) ) ;
100-
101-
102- // Log all results
103- console . log ( {
104- firstCodePoint,
105- thirdCodePoint,
106- wordFromCodePoints,
107- swappedString,
108- } ) ;
87+
88+ // Practice Problem #1
89+ {
90+ // Exercise 1
91+ let inputString = "Hi" ;
92+ let sumCodePoints = inputString . charCodeAt ( 0 ) + inputString . charCodeAt ( 1 ) ;
93+
94+ // Exercise 2
95+ let codePoint1 = 65 ;
96+ let codePoint2 = 66 ;
97+ let combinedString = String . fromCharCode ( codePoint1 ) + String . fromCharCode ( codePoint2 ) ;
98+
99+ // Exercise 3
100+ let inputString2 = "Cat" ;
101+ let index1 = 0 ;
102+ let index2 = 2 ;
103+ let codePointDifference = Math . abs (
104+ inputString2 . charCodeAt ( index1 ) - inputString2 . charCodeAt ( index2 )
105+ ) ;
106+
107+ console . log ( "Practice Problem #1 Results:" ) ;
108+ console . log ( {
109+ sumCodePoints,
110+ combinedString,
111+ codePointDifference,
112+ } ) ;
113+ }
114+
115+ // Practice problem 2
116+ {
117+ // Task 1
118+ let inputString1 = "Code" ;
119+ let firstCodePoint = inputString1 . charCodeAt ( 0 ) ;
120+ let thirdCodePoint = inputString1 . charCodeAt ( 2 ) ;
121+
122+ // Task 2
123+ let wordFromCodePoints = String . fromCharCode ( 72 , 101 , 108 , 108 ) ;
124+
125+ // Task 3
126+ let inputString3 = "Launch" ;
127+ let swappedString =
128+ String . fromCharCode ( inputString3 . charCodeAt ( inputString3 . length - 1 ) ) +
129+ inputString3 . slice ( 1 , - 1 ) +
130+ String . fromCharCode ( inputString3 . charCodeAt ( 0 ) ) ;
131+
132+ console . log ( "\nPractice Problem #2 Results:" ) ;
133+ console . log ( {
134+ firstCodePoint,
135+ thirdCodePoint,
136+ wordFromCodePoints,
137+ swappedString,
138+ } ) ;
139+ }
140+
141+
0 commit comments