London | 26-ITP-January | Eugenie Ahangama | Sprint 1 | coursework/sprint-1 #927
London | 26-ITP-January | Eugenie Ahangama | Sprint 1 | coursework/sprint-1 #927Eugenie-A wants to merge 21 commits intoCodeYourFuture:mainfrom
Conversation
…onvert cardNumber to a string
…alid JavaScript strings
… and replaceAll explanation
…aviour and console output
cjyuan
left a comment
There was a problem hiding this comment.
Code looks good. I just have a few suggestions and questions.
Sprint-1/1-key-exercises/1-count.js
Outdated
| // The = operator assigns a new value to 'count'. It takes the current value of 'count'. | ||
| // adds 1 to it, and then stores that new value back into the 'count' variable. 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?
There was a problem hiding this comment.
I have updated the comment on line 3 to be more concise and included the one word programming term you were asking for: increment.
Sprint-1/1-key-exercises/4-random.js
Outdated
| // Generate a random decimal number between 0 and 1 | ||
| const decimal = Math.random(); |
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, we can say, "Math.random()returns a random number in the interval[0, 1)"
There was a problem hiding this comment.
I've updated the comment to use precise interval notation. It now matches the official Math.random() behaviour (≥ 0 and < 1).
| // 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"): | ||
| // Takes the final two digits of the padded string to form the pence portion |
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?
There was a problem hiding this comment.
After testing: removing .padEnd(2, "0") doesn't change the output for valid inputs (e.g. "399p" → "£3.99") because .padStart(3, "0") already gurantees the last two characters are correctly padded.
So no, you don't really need .padEnd(2, "0") in this code, the output remains correct without it.
| - The console stores a history of messages your code prints while it runs. | ||
|
|
There was a problem hiding this comment.
I think this question is asking, "what properties can be found in the object assigned to the variable console.
I don' think the stores the text that has already been output.
There was a problem hiding this comment.
You are totally right, the question is about the properties/methods of the console object itself, not the output history. Thank you for the feedback!
Learners, PR Template
Self checklist
Changelist
In this project, I completed both the coding exercises and practical exploration of browser based functions using the Chome DevTools console. I tested how different JavaScript features behave, documented my findings and wrote clear explanations in Markdown.
I referred to MDN documentation throughout this project:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
Questions
Are there habits I should start building now to avoid problems later?