-
-
Notifications
You must be signed in to change notification settings - Fork 240
Manchester | 25-ITP-Sep | Mahtem T. Mengstu | Sprint 2 | coursework/sprint-2 #805
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
…, interpreted the error and wrote a new and corrected code.
…and modified the code
… has been writtent and implemented
…int 1 and rearranged it into a reusable function toPounds()
…d modified the code.
Sprint-2/1-key-errors/1.js
Outdated
| function convertToPercentage() { | ||
| const decimalNumber = 0.5; | ||
| const percentage = `${decimalNumber * 100}%`; | ||
|
|
||
| return percentage; | ||
| } |
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.
Without the parameter, the function would always return "50%", which is not very useful.
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.
Without the parameter, the function would always return "50%", which is not very useful.
Thank you for pointing out the case. "decimalNumber" is now taken as a parameter.
| } | ||
|
|
||
| const bmi = weight/(height*height); | ||
| return bmi.toFixed(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.
Both of these function calls output 123 in the console, but internally in the program,
the number 123 and the string "123" are stored and treated differently.
console.log(123);
console.log("123");What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?
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.
Thank you. As I see it in the console it looks like a number whilit was a string. the code has been updated to return a number as -----return Number(bmi.toFixed(1)); which changes the string into number.
|
|
||
| // c) What is the return value of pad is called for the first time? | ||
| // =============> write your answer here | ||
| // =============> 00 |
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.
To more precisely express a value is a string, we can enclsoe the value by a pair of double quotes. For example, "00".
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.
To more precisely express a value is a string, we can enclsoe the value by a pair of double quotes. For example, "00".
Good, I have put it that way "00"
|
|
||
| function formatAs12HourClock(time) { | ||
| let hours = Number(time.slice(0, 2)); | ||
| const minutes = time.slice(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.
We could also pass a parameter to .slice() to clearly express the intent to extract the last two characters,
without needing to calculate the starting position manually. Can you find out what this parameter 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.
We could also pass a parameter to .slice() to clearly express the intent to extract the last two characters, without needing to calculate the starting position manually. Can you find out what this parameter is?
Thank you for pointing out that, we can pass a negative parameter to extract the last two characters.
const minutes = time.slice(-2);
| suffix = "am"; | ||
| } | ||
|
|
||
| hours = hours % 12 || 12; // convert 0 to 12, 13 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.
Can you explain how the expression hours % 12 || 12 convert 0 to 12 and 13 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.
Can you explain how the expression
hours % 12 || 12convert 0 to 12 and 13 to 1?
The expression converts 0 to 12, 13 to 1 and soon as it returns the remainder
for eg. taking 12/12 the remainder is 0
similarly if 13 is taken 13/12 , the remainder is 1, the operator || helps us to return the remainder after
a division operation.
|
|
||
| // Modified Code: | ||
|
|
||
| function formatAs12HourClock(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.
There is another function with the same name defined on lines 6-12. Do you still need that function?
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 another function with the same name defined on lines 6-12. Do you still need that function?
Thank you, I do not need that function, I have commented it out.
…t the function return a number.
…ce(-2) and explained hours = hours % 12 || 12;
Learners, PR Template
Self checklist
Changelist
Completed course works of Sprint 2 from module structuring and testing data
Questions
Questions and blockers will be forwarded to slack.