-
-
Notifications
You must be signed in to change notification settings - Fork 301
London | May-2025 | Mohamed Ibrahim | Sprint-2 #544
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
Sprint-2/2-mandatory-debug/0.js
Outdated
| return a * b; | ||
| } | ||
|
|
||
| console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); No newline at end of file |
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.
What happens when you run this code now? Why doesn't the faulty code give the same error as before?
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.
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.
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.
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?
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.
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.
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.
So how can you change the code in the file so that the multiply function doesn't get called twice?
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.
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.
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.
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 |
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.
Your implementation is good and I like that you tried a few different inputs. However, what is the output when you run this code?
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!
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.
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.
When I run node 1-bmi.js I get
undefined
undefined
undefined
Can you see why?
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 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.
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.
How many times is the calculateBMI function defined in the file?
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 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.
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.
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'
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.
Thanks for the feedback! I think it's sorted out now.
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.
Yeah, I see the changes now. Good job overall. I'll mark this review as complete.
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 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 |
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.
Great job. Code is concise and correct. But is 'input' a good variable name? What might be an alternative?
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!
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.
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.
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 |
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.
Really nice implementation. However you should add some tests.
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.
Thanks! I’ll definitely add some proper tests to make it more clear.
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.
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 |
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.
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?
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.
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".
a-robson
left a comment
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.
Overall this is really good. I've made a few comments - let me know if you want me to expand or discuss.
| 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}`; | ||
| } |
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.
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.
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.
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.
Learners, PR Template
Self checklist
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!