-
-
Notifications
You must be signed in to change notification settings - Fork 301
1exercises #125
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
1exercises #125
Conversation
cjyuan
left a comment
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.
Your repository does not seem right; it contains extra files (but you deleted them "unnaturally") to make the repo contains only files from Sprint-1.
I hope you can manage to "fix" your branch for Sprint-2 and Sprint-3.
| const age = 33; | ||
| /* The value of a constant cannot change through re-assignment, | ||
| we can use var or let insted*/ | ||
| var age = 33; |
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.
Try to avoid using var; it could have weird side effect if not used properly. Use let instead to declare local variables.
| Variable names must begin with a letter, | ||
| underscore, non-number character. Each language has its own conventions.*/ | ||
| const HourClockTime12 = "20:53"; | ||
| const hourClockTime24 = "08:53"; |
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.
(Extra question) Have you also noticed the variable names do not quite match the values assigned to the variable?
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.
Yes, I see the issue you're pointing out. The variable names suggest a certain format for the time, but the values assigned to them don't match that format.
so correct way is:
const HourClockTime12 = "08:53";
const hourClockTime24 ="20:53";
| // 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 | ||
|
|
||
| // eassigning the count variable to a new value by adding 1 to its current value. |
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.
There is a shorter description for statement like count = count + 1. You can try feeding the code to ChatGPT to see how else the code can be described. From time to time you can learn some new terminology or more concise way to describe code.
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.
You're right! The expression count = count + 1 is commonly referred to as an increment operation.
horter description count++
Sprint-1/exercises/decimal.js
Outdated
| // Log your variables to the console to check your answers | ||
| var wholeNumberPart = Math.floor(num); | ||
|
|
||
| var decimalPart = num - Math.floor(num); |
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.
If you run the program, you may notice that console.log() outputs the value of decimalPart with more than 4 decimal places (which is normal because of floating point arithmetic).
If you were asked to print the value of decimalPart to exactly 4 decimal places, how would you modify the code?
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.
Yes, you are right, I added .toFixed(): To format the decimal part to exactly four decimal places.
var decimalPart = (num - Math.floor(num)).toFixed(4);
| // Try breaking down the expression and using documentation to explain what it means | ||
| // It will help to think about the order in which expressions are evaluated | ||
| // Try logging the value of num and running the program several times to build an idea of what the program is doing | ||
| 5.66; |
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 code at line 4 can generate a random number within a specific range. So what are the possible value of num?
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.
I think each time you run the program, a different integer within the range [1, 100] will be generated.
|
|
||
| // 1 | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // The remainder (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.fb |
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.
You gave a literal translation of the code, which may not help one understand what the code is trying to calculate. Can you explain in lament terms what the code is trying to calculate?
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.
You're right that literal explanations might not help make the purpose of the code clear.
"If I divide one number by another, what’s left over after I take away all the full chunks?"
If you have five cookies and try to divide them into groups of 3, you can make one full group (3 cookies). What's left over is two cookies. So, 5 % 3 = 2.
| // calculate the total minutes by subtracting remainingSeconds from movieLength and then dividing by 60 to convert the remaining seconds into minutes | ||
|
|
||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
| // its using tamplat to store variable and any tex /the better name could be time |
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.
"templat to store variable"? What do you mean?
What is tex?
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 variable represents a time format of hours, minutes, and seconds.
formattedTimeString – Emphasizes that the variable holds a string formatted as time.
Time formatted – Indicates the time has been formatted.
timeDisplayString – Suggests that the variable is specifically for displaying time.
Elapsed-time – Implies the time represents the elapsed duration (if that’s the case).
timeFormattedString – A more technical way to express that this is a string of formatted time.
| // The substring() method her returns the part of this string from the start index up to lenght-1 => last one not inclouded then | ||
| // initialises a string variable assign to the result of supStr. | ||
| // 3.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| // initialises a string variable with value of the result of padStart this case it will |
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.
-
Can you describe the rest of the code for general cases? That is, don't assume
penceStringis '399p' but pretend it can be any valid value. For examples, "123456p", "1p", "5500p". So instead of saying "extracting 3 frompenceString", describe the code as "extracting the pound value frompenceString". -
Try using ChatGPT to see how else the code can be described/explained.
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 purpose of this program is to convert a string representing an amount in pence (such as "399p", "123456p", "1p", or "5500p") into a formatted string representing the equivalent amount in pounds and pence.
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.