Skip to content

Birmingham | 26-ITP-Jan | Arun Kumar Akilan | Sprint 2 | Structuring-and-Testing-Data Coursework/Sprint2#1117

Open
arunkumarakilan wants to merge 1 commit intoCodeYourFuture:mainfrom
arunkumarakilan:coursework/sprint-2
Open

Birmingham | 26-ITP-Jan | Arun Kumar Akilan | Sprint 2 | Structuring-and-Testing-Data Coursework/Sprint2#1117
arunkumarakilan wants to merge 1 commit intoCodeYourFuture:mainfrom
arunkumarakilan:coursework/sprint-2

Conversation

@arunkumarakilan
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

This PR contains my completed Sprint 2 coursework for the Structuring and Testing Data module.

Summary of changes:

  • Completed all mandatory debugging exercises
  • Fixed logical errors in existing functions
  • Refactored code into reusable helper functions
  • Implemented string and number formatting functions
  • Handled edge cases such as:
    • Converting 24-hour time to 12-hour format
    • Ensuring consistent two-digit formatting using padStart
  • Ensured functions return correct values instead of relying on console output
  • Tested all exercises to confirm expected behavior

All tasks have been completed and verified to work correctly.


Questions

No questions at this time.

@github-actions

This comment has been minimized.

@arunkumarakilan arunkumarakilan added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 1, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 1, 2026
@arunkumarakilan arunkumarakilan added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 1, 2026
@tee4tao tee4tao added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 1, 2026
@@ -1,5 +1,9 @@
// Predict and explain first...
// Predict and explain first...
//Syntax error
Copy link

Choose a reason for hiding this comment

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

Is this just a generic syntax issue, or is JavaScript specifically telling you something about variable declarations?

Comment on lines +23 to +24
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
Copy link

Choose a reason for hiding this comment

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

You reassigned the parameter instead of redeclaring it.
In small examples this work, but do you think modifying function parameters is a good practice in larger codebases? Why or Why not?

Could you rewrite this function in a way that avoids mutating the parameter entirely?

//Syntax error
// =============> write your prediction here
// We pass str as a parameter to the function.
//The parameter becomes a local variable inside the function scope.
Copy link

Choose a reason for hiding this comment

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

If parameters behave like local variables, why does let cause an error here but var behaves differently? What does that tell you about scope rules?

// =============> write your explanation here
//The error occurred because a local variable was redeclared inside the function using a variable keyword. Since the parameter already acts as a local variable, redeclaring it caused an error.

//To fix this, I removed the variable keyword and modified the existing parameter instead.
Copy link

Choose a reason for hiding this comment

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

In your explanation here, you said you modified the parameter instead of redeclaring it.
But in your final code (which is good), you didn’t modify the parameter, you removed the redeclaration.
Can you clarify what actually changed?

return percentage;
}

const decimalNumber = convertToPercentage(0.5) ;
Copy link

Choose a reason for hiding this comment

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

You name your variable decimalNumber which now holds a percentage string.
Does that variable name still accurately describe the value it contains?

Comment on lines +19 to +20
bmi = bmi.toFixed(1);
return Number(bmi);
Copy link

Choose a reason for hiding this comment

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

You've successfully rounded the number using a string method (.toFixed). If we wanted to avoid converting the number to a string entirely, can you think of a purely mathematical way to round a decimal to one place using Math.round()? (Hint: Think about multiplying and dividing by 10).

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
} No newline at end of file
let bmi = weight / (height * height);
Copy link

Choose a reason for hiding this comment

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

Using height * height works perfectly for squaring! Out of curiosity, are you familiar with any JavaScript operators or Math methods that are specifically designed for calculating exponents?

Comment on lines +19 to +21
str = str.toUpperCase()

return str.replaceAll(" " , "_");
Copy link

Choose a reason for hiding this comment

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

Great job finding the toUpperCase and replaceAll methods! Notice how toUpperCase() returns a new string, and then you apply replaceAll() to that result on the next line. Since both of these are string methods, can you think of a way to connect or 'chain' them together into a single line of code?

// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

function upperSnakeCase(str){
str = str.toUpperCase()
Copy link

Choose a reason for hiding this comment

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

Your code works perfectly, but here you are overwriting the original str variable that was passed into the function. In professional development, we try to avoid changing our input parameters. If you use method chaining (commented about that below), how could you return the final result without ever reassigning the str variable?

const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
time = hours - 12;
Copy link

Choose a reason for hiding this comment

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

In your new logic, you assigned the calculated number to time. While JavaScript allows this, time was originally our input string (e.g., '19:00'). Reassigning parameters to completely different data types can sometimes lead to confusing bugs later on. Can you think of a better way to store your calculated hours - 12 without overwriting the time parameter? Perhaps a new variable name?

@tee4tao tee4tao added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants