Skip to content

Conversation

@sidicamoli
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

In this PR, the necessary changes made and questions answered for Sprint-2 will be presented..
This request encompasses a range of enhancements and the integration of numerous functionalities associated with JavaScript fundamentals

Questions

None for now, thanks!

@sidicamoli sidicamoli added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jun 15, 2025
@a-robson a-robson 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 Jul 1, 2025
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); No newline at end of file
Copy link

Choose a reason for hiding this comment

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

What happens when you run this code now? Why doesn't the faulty code give the same error as before?

Copy link
Author

Choose a reason for hiding this comment

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

When I run this code now, it works correctly and logs:
"The result of multiplying 10 and 32 is 320."
The error doesn’t happen anymore because the multiply function is now properly defined with (return a * b;) statement. Before, it probably didn’t return a value, which caused undefined in the output.

Copy link

Choose a reason for hiding this comment

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

When it is run now the output is

The result of multiplying 10 and 32 is 320
The result of multiplying 10 and 32 is 320

Why does the output appear twice? And why it is that although you haven't amended the original code the 'undefined' error has disappeared?

Copy link
Author

Choose a reason for hiding this comment

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

Because the multiplication function or code is being called or executed two times, causing the same output to print twice. I think because the runtime was reset or refreshed, clearing previous errors or incomplete states that caused the 'undefined' error earlier.

Copy link

Choose a reason for hiding this comment

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

So how can you change the code in the file so that the multiply function doesn't get called twice?

Copy link
Author

Choose a reason for hiding this comment

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

I removed the first version of the multiply function, which only logged the result. Now, there is only one version of the function in the file that uses the "return" command, so the output only appears once.

Copy link

Choose a reason for hiding this comment

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

Yes. Generally you will want to comment out or remove the initial, faulty code example in these exercises.

// Example test cases
console.log(calculateBMI(70, 1.73)); // Expected: 23.4
console.log(calculateBMI(80, 1.8)); // Expected: 24.7
console.log(calculateBMI(50, 1.6)); // Expected: 19.5 No newline at end of file
Copy link

Choose a reason for hiding this comment

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

Your implementation is good and I like that you tried a few different inputs. However, what is the output when you run this code?

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!
When I run the code, the output is:
23.4
24.7
19.5
These match the expected BMI values, so the function is working as intended.

Copy link

Choose a reason for hiding this comment

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

When I run node 1-bmi.js I get
undefined
undefined
undefined
Can you see why?

Copy link
Author

Choose a reason for hiding this comment

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

The undefined output happens because the BMI function didn’t have a return statement. Just like in the earlier multiply example, without return, the function gives undefined when logged. Adding return fixes it.

Copy link

Choose a reason for hiding this comment

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

How many times is the calculateBMI function defined in the file?

Copy link
Author

Choose a reason for hiding this comment

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

The calculateBMI function was defined more than once in the file, which is likely why it was undefined earlier. I’ve now removed the extra definitions, leaving only one function that returns the correct result.

Copy link

Choose a reason for hiding this comment

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

I'm afraid I'm still seeing multiple definitions of the function. Are you sure you committed your changes? If we can sort this out we can move this review to 'Complete'

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I think it's sorted out now.

Copy link

Choose a reason for hiding this comment

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

Yeah, I see the changes now. Good job overall. I'll mark this review as complete.

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 so much! I appreciate your feedback and help throughout the review process. I'm glad it's all good now!


// Example usage:
console.log(toUpperSnakeCase("hello there")); // "HELLO_THERE"
console.log(toUpperSnakeCase("lord of the rings")); // "LORD_OF_THE_RINGS" No newline at end of file
Copy link

Choose a reason for hiding this comment

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

Great job. Code is concise and correct. But is 'input' a good variable name? What might be an alternative?

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!
You're right, I think the input is quite generic. So, a better alternative could be something more descriptive like text, phrase, or sentence to better reflect the expected value. For example:
function toUpperSnakeCase(phrase) {
return phrase.toUpperCase().replace(/ /g, "_");
}
This makes the purpose of the variable clearer.

Copy link

Choose a reason for hiding this comment

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

Yes, 'phrase' is a much better variable name.

// The code "console.log(toPounds("399p"));" shows the price of £3.99.
// The code "console.log(toPounds("50p"));" shows that the amount is £0.50.
// The console.log function displays the value "4p" (which is equivalent to £0.04).
// The code "console.log(toPounds("1234p"));" shows the price of £12.34. No newline at end of file
Copy link

Choose a reason for hiding this comment

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

Really nice implementation. However you should add some tests.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! I’ll definitely add some proper tests to make it more clear.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! I added some tests.

console.assert(
formatAs12HourClock("23:59") === "11:59 pm",
"Failed: 23:59 should be 11:59 pm"
); No newline at end of file
Copy link

Choose a reason for hiding this comment

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

I'd expect 03:22 to be converted to 3:22 am. What would your program return? Another thing to think about it is what would happen if we had invalid input e.g. 25:00?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback!
I’ve updated the function to return "3:22 am" (no leading zero) and added validation for invalid input like "25:00".

Copy link

@a-robson a-robson left a comment

Choose a reason for hiding this comment

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

Overall this is really good. I've made a few comments - let me know if you want me to expand or discuss.

@a-robson a-robson 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 Jul 1, 2025
@sidicamoli sidicamoli added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 2, 2025
Comment on lines 4 to +25
function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
if (hours > 12) {
return `${hours - 12}:00 pm`;
const [hourStr, minuteStr] = time.split(":");

const hours = Number(hourStr);
const minutes = Number(minuteStr);

// Validate input

if (
isNaN(hours) || isNaN(minutes) ||
hourStr.length !== 2 || minuteStr.length !== 2 ||
hours < 0 || hours > 23 ||
minutes < 0 || minutes > 59
) {
return "Invalid time";
}
return `${time} am`;
}

const currentOutput = formatAs12HourClock("08:00");
const targetOutput = "08:00 am";
console.assert(
currentOutput === targetOutput,
`current output: ${currentOutput}, target output: ${targetOutput}`
);
let displayHours = hours % 12 || 12;
const period = hours >= 12 ? "pm" : "am";

return `${displayHours}:${minuteStr} ${period}`;
}
Copy link

Choose a reason for hiding this comment

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

Great implementation. It's quite different from the original and that did make me wonder whether you might have relied a bit too much on ChatGPT or some other AI. If you did use AI my advice is to use it as little as possible at this stage in your development as a programmer. AI can fool you into thinking you've learned something when you're not actually absorbing or retaining information.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I understand your point and take it seriously. I’ve mainly been using AI for guidance to help me understand how to improve or fix my own code, not to copy solutions. Moving forward, I’ll rely more on my own thinking and use AI as a learning tool, not a crutch.

@a-robson a-robson added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jul 2, 2025
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