Skip to content

London | 26-ITP-Sep | Diana Ausiejute | Sprint 3 | Dead Code - #1735

Open
ausiejute wants to merge 6 commits into
CodeYourFuture:mainfrom
ausiejute:coursework/sprint-3-dead-code
Open

ausiejute wants to merge 6 commits into
CodeYourFuture:mainfrom
ausiejute:coursework/sprint-3-dead-code

Conversation

@ausiejute

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1066

Changelist

Completed both exercises, removing dead code.

@ausiejute ausiejute added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 19, 2026
@madhuranakate madhuranakate added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 21, 2026
Comment thread dead-code/exercise-1.js

const greetingMessage = sayHello(greeting, testName);

console.log(greetingMessage); // 'hello, Aman!'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the function being called ? if you run this code, can you see any output ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right!, if there's no associated test, I wouldn't know if it does without it. So if we did have a test for this function, would it be correct to delete the console log method? (i would guess it would depend on the broader context?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Two different ideas get mixed here. Dead code is code that never runs (like the log after return) or whose result is never used (like greetingStr). The last console.log runs and prints the result, so it isn't dead, whether or not there's a test. Whether to keep logs in a real project is a separate choice. Once a test checks what sayHello returns, you often wouldn't need a log to see it working. In this exercise, though, the task is to remove only the dead code, and the exercise 2 instructions name the final console log as the thing that must keep working.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the problem was that I put unreachable, redundant AND unnecessary bits into one bucket.
Lesson: read what's asked a few times, multiple times, and if removing/refactoring, make sure to check if everything still works as expected (and or use tests) :)

Comment thread dead-code/exercise-2.js

const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH);

console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this console log line is removed, how can you see the output ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, i removed too much

@madhuranakate madhuranakate added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 21, 2026
@ausiejute ausiejute added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 21, 2026

@abdishakoor-dev abdishakoor-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting the final console.log back in both files. Exercise 2 is done: only capitalisedPets and logPets have gone and the output matches the original.

One thing left before I can mark it Complete:

  1. dead-code/exercise-1.js: the output has changed. I've left a question on line 10.

Add the Needs Review label again once you've pushed.

Comment thread dead-code/exercise-1.js

testName = "Aman";

const greetingMessage = sayHello(greeting, testName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run this file with node. It prints hello, Jerry!, but the original printed hello, Aman! (the comment you removed from the last line said so). Which deleted line made the difference, and was that line really unused?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, the deleted testName = "Aman"; line made the difference. I was mixing up the comment with the code, that assignment wasn’t unused; it changed the value passed to sayHello. testName also needs to be declared, so if we’re not refactoring the setup, both the declaration and the assignment stay.

@abdishakoor-dev abdishakoor-dev removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 9, 2026
@ausiejute ausiejute added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 9, 2026
@Ade-Adeleke Ade-Adeleke added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 11, 2026
@Ade-Adeleke

Copy link
Copy Markdown

Hi @ausiejute , I ran both files on the final commit (f875ec5) and the output matches the originals: hello, Aman! and { HAMSTER: 3, HORSE: 1 }.

The dead code is removed correctly, and I can confirm the earlier feedback has been addressed.

@Ade-Adeleke Ade-Adeleke added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants