Skip to content
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

Update timer.js #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update timer.js #15

wants to merge 1 commit into from

Conversation

PitPik
Copy link

@PitPik PitPik commented Jan 29, 2023

  • remove repetitive code (document.getElementById, secondsElement.innerHTML =, ...)
  • create setTime() to reduce code repetition
  • clearInterval inside startTimer to avoid accidental multiple intervals
  • use .textContent instead of .innerHTML for performance (and because the numbers are not HTML anyhow but text only)
  • Simplify code (removed ~60% of the code)

- remove repetitive code (document.getElementById, secondsElement.innerHTML =, ...)
- create setTime() to reduce code repetition
- clearInterval inside startTimer to avoid accidental multiple intervals
- use .textContent instead of .innerHTML for performance (and because the numbers are not HTML anyhow but text only)
- Simplify code (removed ~60% of the code)
@PitPik
Copy link
Author

PitPik commented Jan 29, 2023

Hi Vitaly,
I happened to stumble upon your code as I was looking for minesweeper implementations ...
I was looking inside your code and experienced quite some code repetition and inefficient logics.
I picked the timer.js for a "review" as it was the easiest to fix although there is more places that would be worth refactoring.
I can imagine that this project was an exercise for you (back then) and is not important to be refactored ... I sometimes go back to my "old" code myself and try to find out if I improved within the last years and then start refactoring myself. I think this is fun to do.
Hope this PR gave you some ideas and you also have fun with refactoring.

@VitaliyShulik
Copy link
Owner

Hello, thanks for contributing, but did you test it? The main point of the section with the Interval is when the game started to show only seconds (before 60 seconds) or seconds and minutes (after 60 seconds and before 3600 seconds) or seconds, minutes, and hours (after 3600 seconds). Looks like you have cut this feature.

@PitPik
Copy link
Author

PitPik commented Jan 30, 2023

Hmm,... but you had the "00" in your index.html, so it does show the 2 zeroes anyhow. I tested it of course ... and didn't see a difference.

@PitPik
Copy link
Author

PitPik commented Jan 30, 2023

Just ignore all my PRs. I was just having a lot of ideas to reduce code by not "really" changing any logic.
It's not important for me to have those changes on you repo. I just had fun to re-think some ideas.
Greetings :)

@VitaliyShulik
Copy link
Owner

Okay, thanks for clarifying, I didn't touch this code for about 3 years and could forget some features... I will check it as soon as possible and add your contribution to this project. Feel free to add other contributions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants