-
-
Notifications
You must be signed in to change notification settings - Fork 239
Birmingham | 25-ITP-Sep | Joy Opachavalit | Sprint 1 | coursework/sprint-1 #773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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