-
-
Notifications
You must be signed in to change notification settings - Fork 337
Manchester | 26-ITP-Jan | Ofonime Edak| Sprint 3 | Dead Code #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
200135d
74a3301
a9e0b1c
1942553
65c1eac
87fc640
ff49d6c
b2e5292
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,28 @@ | ||
|
|
||
| // Predict and explain first BEFORE you run any code... | ||
| //This code is to take one number function parameter and return area. | ||
|
|
||
| // this function should square any number but instead we're going to get an error | ||
|
|
||
| // =============> write your prediction of the error here | ||
| // =============> write your prediction of the error here. | ||
| // syntaxError: passing an argument instead for a parameter. | ||
|
|
||
| function square(3) { | ||
| return num * num; | ||
| } | ||
|
|
||
| // =============> write the error message here | ||
| //SyntaxError:Unexpected number | ||
|
|
||
| // =============> explain this error message here | ||
| //The function was not expecting number during declaration | ||
|
|
||
| // Finally, correct the code to fix the problem | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| // =============> write your new code here | ||
|
|
||
| //function square(num) { | ||
| // return num * num; | ||
| //} | ||
| //console.log(square(3)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,10 @@ | ||
| // 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); | ||
| } | ||
|
|
||
| testName = "Aman"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is normal to put arguments themselves into variables and, better, constants, instead of pasting raw literals into function arguments. These raw literals are called "magic numbers"/"magic strings" respectively and typically should be avoided. |
||
|
|
||
| const greetingMessage = sayHello(greeting, testName); | ||
| const greetingMessage = sayHello('hello', 'Aman!'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will there be a difference between the output with these arguments compared to the initial arguments? |
||
|
|
||
| console.log(greetingMessage); // 'hello, Aman!' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you analyse please who's calling this function in the file? |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: after we removed the console.log on the line 10, what is the remaining purpose of this string?