-
-
Notifications
You must be signed in to change notification settings - Fork 210
WM | ITP-JAN-25 | HATEF_EIDI | Module-Data-Groups | Sprint 3| Alarm Clock #405
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
illicitonion
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.
This is generally looking good - I left some comments on a few things to think about.
On the testing - how are you trying to run the tests? What happens when you try? Do you get error messages?
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.
It looks like you included files from the Prep in this PR, which should only include the Alarm Clock exercise - please can you remove the prep files from this PR?
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 tried to get rid of the Prep file, however since I pushed the commits to the parent branch (main) whenever I request a pull, the parent changes appear to the PR.
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.
Oh actually I need the title to immediately updates when the set alarm button is clicked in order to pass all the test, without line 6, the code doesn't pass 2 tests, and without line 15 the title don't get updated, so we need both, therefore I changed it back to what it was.
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 recommend sitting with someone in class on Saturday, or on a call, to try to get this fixed. You should be able to remove this file just on your branch. But also if you've accidentally pushed it to your main, you should be able to remove it from there too.
| const diff = alarmTime - currentTime; | ||
|
|
||
| //Updating the time remaining text in the HTML element | ||
| document.getElementById('timeRemaining').innerText="Time Remaining: "+timeFormatter(diff); |
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.
This looks like the same code as is on line 6.
Let's imagine we wanted to change the text it showed from "Time Remaining:" to "Time Left:" - we would need to make sure we remembered to change both lines 6 and 18.
Can you think of a way to make it so that we would only need to change one line of code if we wanted to make that change, rather than two?
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 reason is as soon as the user set alarm the value is added to the title, I can only keep line 18, but the title updates after 1 second interval.
Now removed line 6, which means the title is updated after 1 second, if that needs to be changed and you prefer the user to see the title as soon as they click set alarm button, please let me know so I changed it to what it was 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.
I agree that you need to update the element both when the alarm is set, and when it changes. What I'm asking here is: How can you do that without repeating exactly the same code?
Sprint-3/alarmclock/alarmclock.js
Outdated
| function timeFormatter(seconds) { | ||
| const remainingSeconds= seconds % 60; | ||
| const remainingMinutes = Math.floor(seconds / 60); | ||
| return `${remainingMinutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`; |
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.
This is a bit hard to read because there's quite a lot on one line inside one string literal - could you think of a way to split this up a bit so that there isn't so much going on in one line?
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.
Sure, created a separate function which takes two parameter, min and sec, and return the formatted time to time formatter function
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.
These are much easier to read - thanks!
| const diff = alarmTime - currentTime; | ||
|
|
||
| //Updating the time remaining text in the HTML element | ||
| document.getElementById('timeRemaining').innerText="Time Remaining: "+timeFormatter(diff); |
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 agree that you need to update the element both when the alarm is set, and when it changes. What I'm asking here is: How can you do that without repeating exactly the same code?
| } | ||
|
|
||
| //formatting remaining seconds in the format of MM:SS | ||
| function timeFormatter(seconds) { |
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.
We normally name functions like verbs because they do things - so formatTime rather than timeFormatter. (Same comment applies to timePadder)
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 recommend sitting with someone in class on Saturday, or on a call, to try to get this fixed. You should be able to remove this file just on your branch. But also if you've accidentally pushed it to your main, you should be able to remove it from there too.
Sprint-3/alarmclock/alarmclock.js
Outdated
| function timeFormatter(seconds) { | ||
| const remainingSeconds= seconds % 60; | ||
| const remainingMinutes = Math.floor(seconds / 60); | ||
| return `${remainingMinutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`; |
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.
These are much easier to read - thanks!
Learners, PR Template
Self checklist
Changelist
Alarm Clock project, where the user type the number of seconds in an input, time gets decremented by every second and when time remaining reaches to 0, alarm goes off, and they can stop the alarm by clicking the stop alarm button.
Questions
I couldn't use the jest file, I have no idea how test looks like for testing JavaScript DOM, do we come across it later?