Sheffield | 26-ITP-Jan | Mahmoud Shaabo | Sprint 1 | Module Structuring and Testing Data#976
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Code is quite well written. I mainly have some questions and suggestions.
Sprint-1/1-key-exercises/1-count.js
Outdated
|
|
||
| // Line 1 is a variable declaration, creating the count variable with an initial value of 0 | ||
| // Describe what line 3 is doing, in particular focus on what = is doing | ||
| // The code adds 1 to the count variable. |
There was a problem hiding this comment.
Operation like count = count + 1 is very common in programming, and there is a programming term describing such operation.
Can you find out what one-word programming term describes the operation on line 3?
Sprint-1/1-key-exercises/4-random.js
Outdated
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
|
|
||
| console.log(num); | ||
| // num represents a random integer between 1 and 100. |
There was a problem hiding this comment.
Phrases like "a number between X and Y" are not precise enough in a program specification, because they do not clearly state whether the endpoints X and Y are included.
We can also use the concise and precise interval notation to describe a range of values.
[,]=> inclusion(,)=> exclusion
For example, [1, 10) means, all numbers between 1 and 10, including 1 but excluding 10.
Sprint-1/2-mandatory-errors/3.js
Outdated
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = cardNumber.slice(-4); |
There was a problem hiding this comment.
Suppose you were not allowed to modify the statement const cardNumber = 4533787178994213;
(that is, keep the variable's value unchanged).
How would you modify the code (through type conversion) so that you can still use .slice(-4) to extract the last 4 digits from the given number.
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
|
|
||
| // replaceAll might not work in older Node versions |
There was a problem hiding this comment.
Can you describe why the original code on line 5 does not work? Here is the code:
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
Note: There is an easier way to fix the original code than replacing replaceAll() by replace().
| // 5. const pence = ... | ||
| // It extracts the last two characters to represent the pence part and ensures it has two digits. |
There was a problem hiding this comment.
Could we expect this program to work as intended for any valid penceString if we deleted .padEnd(2, "0") from the code?
In other words, do we really need .padEnd(2, "0") in this script?
…m, interval notation, type conversion, fix syntax error explanation, and clarify padEnd redundancy
|
Hi @cjyuan, Thank you for reviewing my code and for your detailed feedback. I've updated all five files based on your suggestions:
Please let me know if there is anything else I should improve. I appreciate the feedback — it helped me understand these concepts more deeply. Best regards, |
|
Thanks for answering all my questions, and they are all spot on! Excellent job! |
|
Sorry, I beat you on the label. :P |
I have completed the coursework for Sprint 1.
Work done:
2-mandatory-errorsdirectory.3-mandatory-interpretdirectory.Learners, PR Template