From 020503b52fffee1ecdc4a8c97208ff4f94e8f9c3 Mon Sep 17 00:00:00 2001 From: Carol Date: Fri, 23 Oct 2026 22:29:35 +0100 Subject: [PATCH] removed dead and unreachable code from the 2 files --- dead-code/exercise-1.js | 7 +++---- dead-code/exercise-2.js | 9 ++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 4d09f15fa9..32a1b64704 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,16 +1,15 @@ // Find the instances of unreachable and redundant code - remove them! // The sayHello function should continue to work for any reasonable input it's given. -let testName = "Jerry"; const greeting = "hello"; +const testName = "Aman"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; + return `${greeting}, ${name}!`; - console.log(greetingStr); + } -testName = "Aman"; const greetingMessage = sayHello(greeting, testName); diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 56d7887c4c..c642269cfa 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,12 +2,8 @@ // The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable. const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; -const capitalisedPets = pets.map((pet) => pet.toUpperCase()); -const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} +const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); function countAndCapitalisePets(petsArr) { const petCount = {}; @@ -20,9 +16,8 @@ function countAndCapitalisePets(petsArr) { petCount[capitalisedPet] = 1; } }); - return petCount; + return petCount; } - const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log