Cape Town | 26-ITP-September | Sima Nongawuza | Sprint 3 | Coursework/sprint 3 - #1637
simanongawuza wants to merge 11 commits into
Conversation
…matAs12HourClock.
✅ Deploy Preview for cyf-onboarding-module ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
hackertainment
left a comment
There was a problem hiding this comment.
Your work generally looks good to me. Just some minor English presentation issues which may affect accuracy or understanding. Most of my comments are just for your future reference and improvement.
You just need to give a reply to the following comments:
- https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/pull/1637/changes#r4177706484
- https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/pull/1637/changes#r4177757931
And code fix for the following comments:
- https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/pull/1637/changes#r4177771431
- https://github.com/CodeYourFuture/Module-JavaScript-Fundamentals/pull/1637/changes#r4177784337
Thank you for your effort, and keep it up.
|
|
||
| // =============> write your explanation here | ||
|
|
||
| //The code runs but gives undefined in the console when we call the sum(10, 32). The return function is not defined. We must define it a + b so that when we call it, it give the sum of the 2 values |
There was a problem hiding this comment.
Found a typo and should be "... The return value is not defined..." - because precisely speaking, the sum function itself is defined (in line 4) and the return itself is a built-in function (i.e. defined in JavaScript).
| // The const variable must be removed from the code. The computer reads that first and gives the same output for all console.log statements. | ||
| // A placeholder variable for num must be declared in the function parameter. No newline at end of file |
There was a problem hiding this comment.
I think line 33 would be a more accurate explanation. For line 32, even the const num variable is kept in the fixed code, the num.toString() in your function would still use the num in function parameter (when they are the same name). This is the concept of "scope of variable" in JavaScript (and other programming languages as well). So the key issue is "whether the function parameter exist or not", but not quite "whether the global constant variable removed or not".
| //} | ||
| function calculateBMI(weight, height) { | ||
| squareHieght = height * height; | ||
| calculateBMI = Math.round(((weight / squareHieght)) *10 )/10; |
There was a problem hiding this comment.
While your program produce the correct result, the ((weight / squareHieght)) used double brackets. This is not quite recommended - especially in socket programming, single pairs of bracket and double pairs of bracket may yield different results.
| const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); | ||
| const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); | ||
| const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length -2); | ||
| const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length -2).padEnd(2, "0"); |
There was a problem hiding this comment.
Just to clarify a bit, why .padEnd(2, "0") is needed here?
| console.log(toPounds("399p")) | ||
| console.log(toPounds("10p")) | ||
| console.log(toPounds("1023p")) | ||
| console.log(toPounds("5p")) No newline at end of file |
There was a problem hiding this comment.
Your program looks generally ok to me. However, have you think of console.log(toPounds("0000000p")); and would it be the output you wanted? Just to give you a thought first and you don't need to fix the issue at this point, because you will learn more about designing test cases in the later module.
| const hours = Number(time.slice(0, 2)); | ||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| const timeString = String(time); |
There was a problem hiding this comment.
Just wondering why this line is needed?
| return `${time} am`; | ||
| const paddedHours = String(hours).padStart(2, "0"); | ||
| const paddedMinutes = String(minutes).padStart(2, "0"); | ||
| return `${paddedHours}:${paddedMinutes}${period}`; |
There was a problem hiding this comment.
Based on the original given targetedOutput (which has been deleted in your code), there should be a space before period (e.g. 08:00 am but not 08:00am).
| console.log(formatAs12HourClock("00:30")) | ||
| console.log(formatAs12HourClock("23:32")) | ||
| console.log(formatAs12HourClock("08:50")) | ||
| console.log(formatAs12HourClock("13:00")) |
There was a problem hiding this comment.
Your test cases have covered am and pm. However, there are still 3 boundary cases which have not been covered yet. Can you think of them and add them too? Thank you.

Self checklist
Task code
CYF-1053
Changelist
-Completed all mandatory and stretch tasks for Sprint 3.
-Fixed bugs in the debugging exercises.
-Implemented the toPounds function.
-Added edge case tests for the time format exercise