Birmingham | 25-ITP-Sep | Joy Opachavalit | Sprint 1 | coursework/sprint-1#773
Birmingham | 25-ITP-Sep | Joy Opachavalit | Sprint 1 | coursework/sprint-1#773enjoy15 wants to merge 17 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Explanation is very clear and answers are accurate.
I just have a few questions.
|
|
||
| // 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 an assignment statement. The = is the assignment operator, which takes the value on the right side (count + 1, which evaluates to 1) and assigns it to the variable on the left side (count), updating count's value from 0 to 1 |
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.
Operation like
count = count + 1is 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?
@cjyuan increment
|
|
||
|
|
||
| // 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? | ||
| //syntax error! On line 5, there's a missing comma in the replaceAll method. |
There was a problem hiding this comment.
In the function call .replaceAll(",", ""), there's a programming term for "," and "" (the values passed into the function). Could you find out what this term is?
| // 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing 'p' from the string to isolate the numeric part | ||
| // 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the numeric string with leading zeros to ensure it is at least 3 digits long | ||
| // 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion from the padded string | ||
| // 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion and ensures it is 2 digits long |
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.
No, we don't need .padEnd(2, "0") in this script. —Since padStart(3, "0") ensures the string is minimum 3 characters, and we're extracting the last 2, we'll always get exactly 2 characters. The .padEnd(2, "0") is redundant.
| -> It displays a dialog box in the browser asking the user to enter some input. | ||
| The user can type a response and click "OK" or click "Cancel". |
There was a problem hiding this comment.
What value does prompt() return? How can the program that call prompt() find out if the user clicked OK or Cancel?
There was a problem hiding this comment.
The prompt() function returns different values depending on what the user does:
1. If the user types something and clicks "OK": prompt() returns a string containing whatever the user typed
◦ Even if they type nothing and click OK, it returns an empty string ""
2. If the user clicks "Cancel" (or presses ESC): prompt() returns null
The return value is either a string (including empty string "") or null. This null value is how the program knows the user clicked Cancel rather than OK.
|
Spot on! Great work! In the PR description, Can you change "#Changelist" to a level-2 header in Markdown, to make it look like this? Changelist |
|
@cjyuan I have changed "#Changelist" to a level-2 header in Markdown. |
Learners, PR Template
Self checklist
Changelist
-Completed all excercises in Sprint-1