London | 26-Jan-ITP | Shuheda Begum | Sprint 2 | Coursework#1070
London | 26-Jan-ITP | Shuheda Begum | Sprint 2 | Coursework#1070codebyshay wants to merge 10 commits intoCodeYourFuture:mainfrom
Conversation
I added the description the term increment
Restored 3.js to original text and made a prediction about the use of slice
I updated the code and ran it to test. The code worked and logged the last for digits of the card, 4213.
| return str; | ||
| if (!str) return str; // handles empty string | ||
| return str[0].toUpperCase() + str.slice(1); | ||
| } |
There was a problem hiding this comment.
Good thinking to consider handling the empty string error.
Sprint-2/2-mandatory-debug/1.js
Outdated
| // Write your explanation here | ||
| // When JavaScript sees the 'return' statement, it immediately stopd the function. |
There was a problem hiding this comment.
Yes, this is correct. You can read more on the exact operation; it is called in JavaScript. I man the termination of the function when the return keyword appears on its own line
| function toPounds(penceString) { | ||
| 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"); | ||
|
|
||
| return `£${pounds}.${pence}`; | ||
| } |
There was a problem hiding this comment.
I understand you used the context of the code in the previous sprint, but this code could have been written in a much cleaner way by using some other functions to perform some conversions to the string. You can have a read on that as you progress.
| `current output: ${currentOutput2}, target output: ${targetOutput2}` | ||
| ); | ||
| //testing the function with various inputs. | ||
| console.log(formatAs12HourClock("08:00")); // 08:00 am |
There was a problem hiding this comment.
You need to write tests for various time formats. Unit tests, not console.log statements.
There was a problem hiding this comment.
Hi, I will type the answer here. there seems to be a conflict with my work and when I'm saving the work and adding a commit, its not being pushed. I fear this may be due to an issue I had with the branch previously, which led me to starting over again. I had the same issue with Sprint One. I don't have the opportunity to start over again, as all work had to be submitted by yesterday, I will save my answers here. I hope that ok.
import { formatAs12HourClock } from "./formatAs12HourClock";
describe("formatAs12HourClock", () => {
test("formats morning time correctly", () => {
expect(formatAs12HourClock("08:00")).toBe("08:00 am");
});
test("formats evening time correctly", () => {
expect(formatAs12HourClock("23:00")).toBe("11:00 pm");
});
test("formats midnight correctly", () => {
expect(formatAs12HourClock("00:30")).toBe("12:30 am");
});
test("formats noon correctly", () => {
expect(formatAs12HourClock("12:15")).toBe("12:15 pm");
});
test("formats afternoon time correctly", () => {
expect(formatAs12HourClock("13:45")).toBe("01:45 pm");
});
test("formats late morning correctly", () => {
expect(formatAs12HourClock("11:59")).toBe("11:59 am");
});
test("formats exactly noon", () => {
expect(formatAs12HourClock("12:00")).toBe("12:00 pm");
});
});
| let [hours, minutes] = time.split(":"); | ||
| hours = Number(hours); | ||
| let period = "am"; | ||
|
|
||
| if (hours === 0) { | ||
| hours = 12; // midnight | ||
| } else if (hours === 12) { | ||
| period = "pm"; // noon | ||
| } else if (hours > 12) { | ||
| hours -= 12; | ||
| period = "pm"; |
There was a problem hiding this comment.
Good solution to the bugs present in the code.
Theoreoluwa
left a comment
There was a problem hiding this comment.
Great job, Shuheda. Please look at my comments for better improvement. Keep going!
|
Thank you. I am having trouble saving and committing the changes, so have posted the answers to any questions on here. I hope that ok. Thank you. |
|
I’ll look through your comments. Your pr contains a conflict. That’s why it’s giving you issues when you want to commit and raise another pr. |
|
Yes, I'm not sure how to resolve it 🥺 |
|
Looking at your answers, the test script you put in the comments were written using the Jest test suite. The code within the task gives you a little template on how to write tests as required for the function within the code. You should apply that as it helps solidify your idea of feature testing at this level. Rather than using a test suite for it. I'll be marking your work as done as the test task isn't entirely mandatory. |
|
Thank you so much. I will definitely look into what you said. Hopefully this weekend at class I can get some help with the conflict too. |
Learners, PR Template
Self checklist
Changelist
Completed all task required for Sprint 2
Questions
No questions.