From d9e5dc0ed09a7c166f4d137ae1568e53a6904de9 Mon Sep 17 00:00:00 2001 From: JavaAndroi Date: Tue, 28 Jul 2026 15:48:12 -0400 Subject: [PATCH] Refactor unicode.js to complete tasks with code points --- unicode.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/unicode.js b/unicode.js index 1710ed5..d1bc8e1 100644 --- a/unicode.js +++ b/unicode.js @@ -84,17 +84,21 @@ Assign the result to a variable named swappedString. */ //Starter Code -// Task 1 -let inputString1 = "Code"; -let firstCodePoint; // Your code here -let thirdCodePoint; // Your code here +// Task 1const string1 = "Code"; +const firstCodePoint = string1.charCodeAt(0); // 'C' +const thirdCodePoint = string1.charCodeAt(2); // 'd' + +console.log(firstCodePoint); // 67 +console.log(thirdCodePoint); // 100 // Task 2 -let wordFromCodePoints; // Your code here +// Your code here // Task 3 -let inputString2 = "Launch"; -let swappedString; // Your code here + Your code hereconst codePoints = [72, 101, 108, 108]; +const wordFromCodePoints = String.fromCharCode(...codePoints); + +console.log(wordFromCodePoints); // "Hell" // Log all results console.log({ @@ -103,3 +107,10 @@ console.log({ wordFromCodePoints, swappedString, }); +const originalString = "Launch"; +const firstCharCode = originalString.charCodeAt(0); // 'L' +const lastCharCode = originalString.charCodeAt(originalString.length - 1); // 'h' + +const swappedString = String.fromCharCode(lastCharCode) + originalString.slice(1, -1) + String.fromCharCode(firstCharCode); + +console.log(swappedString); // "hauncL"