London | 26-ITP-Jan | Alex Okorefe | Sprint 1 | Coursework#1010
London | 26-ITP-Jan | Alex Okorefe | Sprint 1 | Coursework#1010Alex-Os-Dev-Lab wants to merge 12 commits intoCodeYourFuture:mainfrom
Conversation
Utilized prettier to format code in (1-count.js; 2-initials.js; 3-paths.js)
…atement to fix error
…nd rationale of the program
2ea8486 to
af47636
Compare
| // 2. Then Math.random() is called, which generates a random decimal number between 0 and 1. | ||
| // 3. The result of Math.random() is multiplied by the result of step 1, giving us a random decimal number between 0 and 100. | ||
| // 4. Math.floor() is then called on the result of step 3, which rounds it down to the nearest whole number, giving us a random integer between 0 and 99. | ||
| // 5. Finally, the minimum value (1) is added to the result of step 4, giving us 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 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.
| 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.
| // Function calls are determined by the presence of parentheses "()" after a function name. | ||
| // Therefore in this file, there are 6 function calls: |
There was a problem hiding this comment.
Which 6? There should be less than 6 function calls in the code.
| // f. Therefore, if the paddedPenceNumberString variable has a length of less than 2 characters, the padEnd method will add "0" characters | ||
| // to the end of the string until it reaches a total length of 2 characters. | ||
| // In this case, since paddedPenceNumberString is "399" which has a length of 3 characters, | ||
| // the substring method will extract the last two characters "99" | ||
| // and then the padEnd method will not add any padding since the length of the resulting string is already 2 characters. | ||
| // therefore pence will be "99" | ||
|
|
||
| // g. if penceString = "9p" ; const penceStringWithoutTrailingP = "9" ; const paddedPenceNumberString = "009" ; | ||
| // const pounds = "0" ; const pence = "09" because the substring method will extract the last two characters "09" | ||
| // and then the padEnd method will not add any padding since the length of the resulting string is already 2 characters. | ||
| // therefore pence will be "09" |
There was a problem hiding this comment.
Very thorough analysis.
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
Completed the JavaScript tasks
Questions
No questions for now