Repository navigation
London | 26 ITP SEP | Russom Gebremeskel | Sprint 3 | Coursework #1520
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 31 commits
1df46e8
f00caed
507f02a
6f4e46f
9aadee0
6018cd5
444757f
8245202
4064cd8
2bdebf4
849b970
c3b0ad5
0f95d9b
7b9c2e2
e4bb558
3eee2ad
6bece94
5eba71d
8ecde42
8c33243
7d6f51d
db95486
70e2b1b
47cee31
a7d328c
21c9992
172a529
b0d0f7c
f39cb79
6a61eb2
0758ad4
ba0c107
9582109
2565244
5b9c56b
7d884f5
e2a9087
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 |
|---|---|---|
|
|
@@ -4,3 +4,16 @@ | |
| // 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 toPound(priceInPence) { | ||
|
Contributor
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. Two things here. The task asks for a function called
Author
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. I tested it with: 0, 00, 000, 01, 9, 58749 ...
Contributor
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. Good inputs. Please add those calls to this file, after line 19. Line 8 still says
Author
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. Function name changed to toPounds from toPound. Function checked for the following input: 0, 00, 000, 01, 9, 58749
Contributor
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.
One note. This does not stop Complete. Three of your inputs have no |
||
| const penceDigits = priceInPence | ||
| .substring(0, priceInPence.length - 1) | ||
| .padStart(3, "0"); | ||
|
|
||
| const poundsPart = penceDigits.substring(0, penceDigits.length - 2); | ||
|
|
||
| const pencePart = penceDigits.substring(penceDigits.length - 2); | ||
|
|
||
| return `£${poundsPart}.${pencePart}`; | ||
| } | ||
| console.log(toPound("399p")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ function formatTimeDisplay(seconds) { | |
|
|
||
| return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; | ||
| } | ||
| console.log(formatTimeDisplay(61)) | ||
|
|
||
| // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit | ||
| // to help you answer these questions | ||
|
|
@@ -23,16 +24,27 @@ function formatTimeDisplay(seconds) { | |
| // a) When formatTimeDisplay is called how many times will pad be called? | ||
| // =============> write your answer here | ||
|
|
||
| // pad is called 3 times. | ||
|
|
||
| // Call formatTimeDisplay with an input of 61, now answer the following: | ||
|
|
||
| // b) What is the value assigned to num when pad is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| // The value that assigned to num is 0 | ||
|
|
||
| // c) What is the return value of pad when it is called for the first time? | ||
| // =============> write your answer here | ||
|
|
||
| // The return value of pad is: "00" | ||
|
|
||
| // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
|
|
||
| // The value assigned to num is 1. This is because 1 is the last character in the string 61 | ||
|
Contributor
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. The value 1 is right, but have another look at why.
Author
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. 61 % 60 is 61 divided by 60 which is 1(totalMinutes) and the leftover 1 assigned to remainingSeconds
Contributor
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. Yes, this part of your reply is right:
But your answers in the file give a different reason. Please change two lines:
Line 50 is already right. Keep it.
Contributor
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. Fixed. |
||
|
|
||
| // e) What is the return value of pad when it is called for the last time in this program? Explain your answer | ||
| // =============> write your answer here | ||
|
|
||
| // The return value is "01". when pad is called for the last time it takes the last character of the string 61. | ||
| // After checking remainingSeconds length which is less than 2 it adds a "0" and returns "01" | ||
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.
Run this file with node. What happens? The original code on lines 11 to 14 still runs. It stops the file with a SyntaxError, so your fix never runs. How can you keep the original in the file but stop it running?
1.jsand2.jshave the same problem.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.
Commented out code in 0.js, 1.js, and 2.js to stop error throwing.
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.
Fixed now. All three files run without an error.