From 5410ad1cf01c3081866610d2dd443bea133ee3ce Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 18 Oct 2026 01:16:32 +0100 Subject: [PATCH 1/6] commented all the redundant code and checked for the out put, it works --- dead-code/exercise-1.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index 4d09f15fa9..b83fbbc4dd 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,17 +1,17 @@ // 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"; +//let testName = "Jerry"; const greeting = "hello"; function sayHello(greeting, name) { - const greetingStr = greeting + ", " + name + "!"; + //const greetingStr = greeting + ", " + name + "!"; return `${greeting}, ${name}!`; - console.log(greetingStr); + //console.log(greetingStr); } -testName = "Aman"; +//testName = "Aman"; -const greetingMessage = sayHello(greeting, testName); +//const greetingMessage = sayHello(greeting, testName); -console.log(greetingMessage); // 'hello, Aman!' +console.log("hi", "jerry"); // 'hello, Aman!' From 74e28e22b15e23a46395b3bf94f01d2c79e35491 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Sun, 18 Oct 2026 01:26:28 +0100 Subject: [PATCH 2/6] refractored the code --- dead-code/exercise-1.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/dead-code/exercise-1.js b/dead-code/exercise-1.js index b83fbbc4dd..8b406253ae 100644 --- a/dead-code/exercise-1.js +++ b/dead-code/exercise-1.js @@ -1,17 +1,5 @@ -// 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"; - -function sayHello(greeting, name) { - //const greetingStr = greeting + ", " + name + "!"; - return `${greeting}, ${name}!`; - //console.log(greetingStr); +function sayHello(greeting, fname) { + return `${greeting}, ${fname}!`; } -//testName = "Aman"; - -//const greetingMessage = sayHello(greeting, testName); - -console.log("hi", "jerry"); // 'hello, Aman!' +console.log(sayHello(greeting, fname)); From e73ec3c5d71b30f11d7bdd05d95673a79951ae29 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Mon, 19 Oct 2026 12:33:45 +0100 Subject: [PATCH 3/6] commented some cods to understand the code better --- dead-code/exercise-2.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 56d7887c4c..a5082c927c 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,12 +2,12 @@ // 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 capitalisedPets = pets.map((pet) => pet.toUpperCase()); const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -function logPets(petsArr) { - petsArr.forEach((pet) => console.log(pet)); -} +//function logPets(petsArr) { +// petsArr.forEach((pet) => console.log(pet)); +//} function countAndCapitalisePets(petsArr) { const petCount = {}; From 611bdfc230f18babc22c5c935834c708b64d8329 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 23 Oct 2026 23:26:47 +0100 Subject: [PATCH 4/6] deleted the second line of the code which turns the pet to upper case --- dead-code/exercise-2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index a5082c927c..0b5c6972b5 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -2,7 +2,6 @@ // 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) { From cb49d1d8ecf601cf83890a454b399b01da427d67 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 23 Oct 2026 23:28:31 +0100 Subject: [PATCH 5/6] deleted the function logPets --- dead-code/exercise-2.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index 0b5c6972b5..b1c2362d34 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -4,10 +4,6 @@ const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"]; const petsStartingWithH = pets.filter((pet) => pet[0] === "h"); -//function logPets(petsArr) { -// petsArr.forEach((pet) => console.log(pet)); -//} - function countAndCapitalisePets(petsArr) { const petCount = {}; From f541cc8571bce4fad9fbc134c439439177432395 Mon Sep 17 00:00:00 2001 From: Maharit Belai Date: Fri, 23 Oct 2026 23:31:12 +0100 Subject: [PATCH 6/6] const countedPetsStartingWithH and replaced the variable in console.log --- dead-code/exercise-2.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dead-code/exercise-2.js b/dead-code/exercise-2.js index b1c2362d34..443c0345c3 100644 --- a/dead-code/exercise-2.js +++ b/dead-code/exercise-2.js @@ -18,6 +18,4 @@ function countAndCapitalisePets(petsArr) { return petCount; } -const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); - -console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log +console.log(countAndCapitalisePets(petsStartingWithH)); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log