Skip to content

Commit 822fa7a

Browse files
authored
Clean up sayHello function and fix logging
Removed unreachable code and redundant variable.
1 parent b4cbc57 commit 822fa7a

1 file changed

Lines changed: 1 addition & 25 deletions

File tree

Sprint-3/3-dead-code/exercise-1.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
// Find the instances of unreachable and redundant code - remove them!
2-
// The sayHello function should continue to work for any reasonable input it's given.
3-
4-
let testName = "Jerry";
5-
const greeting = "hello";
6-
7-
function sayHello(greeting, name) {
8-
const greetingStr = greeting + ", " + name + "!";
9-
return `${greeting}, ${name}!`;
10-
console.log(greetingStr);
11-
}
12-
13-
testName = "Aman";
14-
15-
const greetingMessage = sayHello(greeting, testName);
16-
17-
console.log(greetingMessage); // 'hello, Aman!'
18-
19-
//I have removed "const greetingStr = greeting + ", " + name + "!";" because it serves the same purpose as "return `${greeting}, ${name}!`;",
20-
//making it redundant.
21-
22-
//Also, "console.log(greetingStr);" comes after "return `${greeting}, ${name}!`;", making it unreachable inside the function, since eveything
23-
//after "return" is ignored.
24-
251

262
let testName = "Jerry";
273
const greeting = "hello";
@@ -34,4 +10,4 @@ testName = "Khaliun";
3410

3511
const greetingMessage = sayHello(greeting, testName);
3612

37-
console.log(greetingMessage); // "hello, Khaliun!"
13+
console.log(greetingMessage);

0 commit comments

Comments
 (0)