Repository navigation
Conversation
|
|
||
| const greetingMessage = sayHello(greeting, testName); | ||
|
|
||
| console.log(greetingMessage); // 'hello, Aman!' |
There was a problem hiding this comment.
is the function being called ? if you run this code, can you see any output ?
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) :)
|
|
||
| const countedPetsStartingWithH = countAndCapitalisePets(petsStartingWithH); | ||
|
|
||
| console.log(countedPetsStartingWithH); // { 'HAMSTER': 3, 'HORSE': 1 } <- Final console log |
There was a problem hiding this comment.
if this console log line is removed, how can you see the output ?
abdishakoor-dev
left a comment
There was a problem hiding this comment.
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:
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.
|
|
||
| testName = "Aman"; | ||
|
|
||
| const greetingMessage = sayHello(greeting, testName); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
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. |
Learners, PR Template
Self checklist
Task code
CYF-1066
Changelist
Completed both exercises, removing dead code.