-
-
Notifications
You must be signed in to change notification settings - Fork 310
London | 26-ITP-Jan | Zadri Abdule | Sprint 2 | Coursework #966
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
0fc35ed
f4e38d3
8a162e3
2bf3487
54ca144
ff14721
97dc683
2f8d74e
c52e087
0de1e19
a451eda
083a9d2
f4c8d85
2776d16
9b67723
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,14 +1,20 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // =============> write your prediction here | ||
|
|
||
| // It will show a undefined error | ||
| function multiply(a, b) { | ||
| console.log(a * b); | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); | ||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)} | ||
|
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. Is this line of code complete? |
||
|
|
||
| // =============> write your explanation here | ||
|
|
||
| // The function printed the answer but did't return it, so when it was used in the template string, it came out as 'undefined.' | ||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
|
|
||
| console.log(`The result of multipying 10 and 32 is ${multiply(10, 32)}`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // Predict and explain first... | ||
| // =============> write your prediction here | ||
| // I predict it will show a undefined error | ||
|
|
||
| function sum(a, b) { | ||
| return; | ||
|
|
@@ -9,5 +10,11 @@ function sum(a, b) { | |
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
|
|
||
| // =============> write your explanation here | ||
| // The problem was the semicolon after return, which made the function stop before adding the numbers | ||
|
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 review the code you have written below as the solution and the previous code to understand why the previous function (before your solution) raised an error and update the explanation? |
||
| // Finally, correct the code to fix the problem | ||
| // =============> write your new code here | ||
| function sum(a, b){ | ||
| return a + b; // Once I put a + b on the same line as return, it worked | ||
| } | ||
|
|
||
| console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,13 @@ | |
| // You will need to declare a function called toPounds with an appropriately named parameter. | ||
|
|
||
| // You should call this function a number of times to check it works for different inputs | ||
| function formatPenceToPounds(penceString){ | ||
| const penceStringWithoutTrailingP = penceString.substring(0, penceString.length -1); | ||
|
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. Is this variable in use when the function is called (or at all)? |
||
| const pounds = paddedPenceNumberString.slice(0, -2); | ||
| const pence = paddedPenceNumberString.slice(-2); | ||
| return `£${pounds}.${pence}`; | ||
|
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. Check on the indentation here |
||
| } | ||
|
|
||
| console.log(formatPenceToPounds("9p")); | ||
| console.log(formatPenceToPounds("39p")); | ||
| console.log(formatPenceToPounds("399")); | ||
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.
Always double-check to avoid typos in the comments that could lead to confusion (small detail that means a lot)