Skip to content

Conversation

iteddy16
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

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.

@iteddy16 iteddy16 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jun 13, 2025
Copy link

@Amundeep-Dhaliwal Amundeep-Dhaliwal left a 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)}`;

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) {

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);

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I removed it.
code2

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
const bmi = weight / (height * height);

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"

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the comment part with the updated output.
code


// 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

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the correction. I think this is how it is executed.
code5

// 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:

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed my error in here.
code6


// 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

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"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code6


// 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.

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}`
);

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}`
  )
}

@Amundeep-Dhaliwal Amundeep-Dhaliwal added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 2, 2025
@iteddy16
Copy link
Author

iteddy16 commented Jul 3, 2025

Thank you @Amundeep-Dhaliwal for your insightful review, I addressed all the raised issues.

@Amundeep-Dhaliwal
Copy link

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 Amundeep-Dhaliwal added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jul 4, 2025
@iteddy16
Copy link
Author

iteddy16 commented Jul 4, 2025

@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.
Here is my Sprint-3 PR Link: #602
Thank you,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Volunteer to add when work is complete and all review comments have been addressed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants