-
-
Notifications
You must be signed in to change notification settings - Fork 219
LONDON | ITP-MAY-25 | TEWODROS BEKERE | Coursework/sprint 2 #540
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
Conversation
This reverts commit 01079c2.
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.
Hello Tewodros, hope you are well.
Thank you for your patience and submitting this work. I have only reviewed the sprint 2 work.
It is good practice to have multiple pull requests for different pieces of work.
// =============> write your new code here | ||
// Here is the corrected function: | ||
function capitalise(str) { | ||
str = `${str[0].toUpperCase()}${str.slice(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.
Reusing the same variable name solves this issue. Looks good.
Bear in mind for a more complicated program it could be confusing to reuse the same variables.
// Finally, correct the code to fix the problem | ||
|
||
// =============> write your new code here | ||
function square(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.
Adding the parameter is good
// Finally, correct the code to fix the problem | ||
// =============> write your new code here | ||
function getLastDigit(num) { | ||
return num.toString().slice(-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.
Recognising that we need a parameter here was the main exercise, good job.
It would be nice for you to remove the const num = 103
on line 9.
You could test getLastDigit
with the numbers from above?
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.
function calculateBMI(weight, height) { | ||
// return the BMI of someone based off their weight and height | ||
} | ||
const bmi = weight / (height * height); |
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.
This looks good.
} | ||
|
||
// Example usage: | ||
console.log(toUpperSnakeCase("lord of the rings")); // Output: "HELLO_THERE" |
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 function works as expected, nice one.
Remember to update the comment with the updated output.
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.
|
||
// b) What is the value assigned to num when pad is called for the first time? | ||
// =============> write your answer here | ||
// 1, which is the value of totalHours when seconds is 61 |
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 first time pad is called with the totalHours
input, the num parameter has the value of 0.
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.
// c) What is the return value of pad is called for the first time? | ||
// =============> write your answer here | ||
// "01", because pad converts the number 1 to a string and pads it with a leading zero to make it two characters long | ||
// Call formatTimeDisplay with an input of 3661, now answer the following: |
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.
Thinking outside of the box for this one.
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.
|
||
// c) What is the return value of pad is called for the first time? | ||
// =============> write your answer here | ||
// "01", because pad converts the number 1 to a string and pads it with a leading zero to make it two characters 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.
pad(totalHours)
would have the return value of "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.
|
||
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer | ||
// =============> write your answer here | ||
// 1, which is the value of remainingSeconds when seconds is 3661. The totalHours is 1, remainingMinutes is 1, and remainingSeconds is 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.
The output when pad is called for the last time in this program is "01"
.
As you said remainingSeconds has the value of 1.
console.assert( | ||
currentOutput3 === targetOutput3, | ||
`current output: ${currentOutput3}, target output: ${targetOutput3}` | ||
); |
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.
Well done for completing the extension here.
This solution works for the test cases that you have defined.
A point to consider for this program:
Inputting 12:00 gives 12:00 am
as the output, 12:00 in 24 hour time is noon.
Only for reference, here is a tested example that also handles minutes:
function pad(num) {
//adds leading 0s to string until it reaches length 2
return num.toString().padStart(2, "0");
}
function formatAs12HourClock(time) {
if (!/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/.test(time)) { //if string DOESN'T look like HH:MM, min 00:00/max 23:59
console.log(`You entered "${time}". formatAs12HourClock only works for times written HH:MM. min 00:00, max 23:59.`);
return;
}
let suffix = ""
let hours = Number(time.slice(0,2)); //convert to number to enable comparisons in if statement
const mins = time.slice(3);
if (hours==0) { // if time entered was 00:MM, then it's midnight and the time has just flipped to am
hours = 12; // in 12 hours clock, 00 is not allowed, so add 12 => 12:00 am for midnight
suffix = "am"
}
else if (hours<12) { // hours 1 through 11 are am hours
suffix = "am"
}
else if (hours==12) { // at midday, the time flips to pm
suffix = "pm"
}
else { // hours > 12 => time is in the afternoon/night
hours=hours-12;
suffix = "pm"
}
return `${pad(hours)}:${mins} ${suffix}`
}
const testStrings = {
"08:00":"08:00 am",
"23:00":"11:00 pm",
"12:00": "12:00 pm",
"13:15": "01:15 pm",
"11:11": "11:11 am",
"03:15": "03:15 am",
"00:05": "12:05 am",
"00:00": "12:00 am",
}
for (const [input, output] of Object.entries(testStrings)){
const currentOutput = formatAs12HourClock(input);
console.assert(
output === currentOutput,
`input: ${input} desired output: ${output}, actual output: ${currentOutput}`
)
}
Thank you @Amundeep-Dhaliwal for your insightful review, I addressed all the raised issues. |
Hello Tewodros, Thanks for making improvements and your screenshots. From a sprint 2 perspective this PR is complete. Can you please raise a new PR with all the sprint 3 work? |
@Amundeep-Dhaliwal, here is my Sprint-3 PR link. The reason my first part of Sprint 3 was included in Sprint 2 was that I forgot to change my branch from Sprint 2 to Sprint 3. |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
In this Sprint 2 exercise, I fix errors in the code and debug codes.
Questions
Ask any questions you have for your reviewer.