London | 26-ITP-Jan | Gloria Mankrado | Sprint 1 |Sprint-1#1108
London | 26-ITP-Jan | Gloria Mankrado | Sprint 1 |Sprint-1#1108gloriamanks wants to merge 3 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
I noticed some inconsistency in the formatting of the code.
Consider install prettier VSCode extension and enable formatting on save/paste on VSCode as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
| // 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 | ||
|
|
||
| // Line 3 is updating the value of the count variable. The = operator is an assignment operator, which assigns the value on the right (count + 1) to the variable on the left (count). In this case, it takes the current value of count (which is 0), adds 1 to it, and then assigns the result (1) back to count. So after this line executes, count will have a new value of 1. No newline at end of file |
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?
|
|
||
| console.log(`num is ${num}`); |
There was a problem hiding this comment.
Can you give a precise description what each of these expressions does, and the range of the numbers it may produce?
Math.random()Math.random() * (maximum - minimum + 1)Math.floor(Math.random() * (maximum - minimum + 1))Math.floor(Math.random() * (maximum - minimum + 1)) + minimum
Note: To describe a range of numbers, we can use the concise and precise interval notation:
[,]=> inclusion(,)=> exclusion
For example, [1, 10) means, all numbers between 1 and 10, including 1 but excluding 10.
There was a problem hiding this comment.
You fixed the error.
You were supposed to also answer questions (a)-(e) in this file.
Any way, for question (b), the error occurred because a comma was missing between the ___________s.
What is the programming term that belongs in the blank?
There was a problem hiding this comment.
Can you also answer questions (a)-(f) in this file?
| // 5. extract the last two characters as the pence amount and pad right with a zero if needed | ||
| const pence = paddedPenceNumberString | ||
| .substring(paddedPenceNumberString.length - 2) | ||
| .padEnd(2, "0"); |
There was a problem hiding this comment.
Optional challenge:
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?
Learners, PR Template
Self checklist
Changelist
excerise 1
updated exercise 1 to include comment
updated excerise 2 to extract the zero based index of each variable names
updated excerise 3 to find the pathway directory and also the file after the forward slash
updated excerise 4 to extract the environment variable of num using $
excerise 2 & 3
converted a pence string into a pounds-and-pence
formatted output, then added detailed comments to explain each calculation step.
This program takes a string representing a price in pence
The program then builds up a string representing a price in pounds