Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

London Class No 7 - Nigel Pelvin - Javascript Core 2 - Week 3#27

Open
nPelvin wants to merge 1 commit intoCodeYourFuture:mainfrom
nPelvin:main
Open

London Class No 7 - Nigel Pelvin - Javascript Core 2 - Week 3#27
nPelvin wants to merge 1 commit intoCodeYourFuture:mainfrom
nPelvin:main

Conversation

@nPelvin
Copy link
Copy Markdown

@nPelvin nPelvin commented Mar 2, 2021

Mandatory exercise functions built with some basic styling.
These will be updated and improved during the week.

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Mandatory exercise functions built with some basic styling.
These will be updated and improved during the week.
Copy link
Copy Markdown

@AhmadJanah AhmadJanah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nigel,

I reviewed your code, and I left some comments.

However, you really did very amazing work. congratulation.

Regards,

@@ -1,4 +1,31 @@
function setAlarm() {}
function refresh(){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nigel,

Well done. you have accomplished it.

I know you did the requirements, but as an extra challenge. try to input 15 seconds as an example and press (set alarm), after 2 or 3 seconds press it again. Can you solve it??

Regards,




function autoForward(){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Nigel.

Could you try to call the forward and backward functions in the auto functions instead of repeating the code?

Regards,

let alarmTime = document.getElementById("alarmSet").value;
let minutes = Math.floor(alarmTime / 60);
let seconds = alarmTime % 60;
document.getElementById("timeRemaining").innerHTML=`Time Remaining: ${minutes.toLocaleString(undefined,{minimumIntegerDigits: 2})}:${seconds.toLocaleString(undefined,{minimumIntegerDigits: 2})}`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nigel, You have done great job. I did not know how to use tolocaleString and minimumIntegerDigit. I am really happy to learn from you! thanks!

Copy link
Copy Markdown

@Jpsi Jpsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job getting the alarm clock to work! 🙂

I'd recommend breaking your code down using more functions - this will make it more structured and readable.

For example, instead of using an anonymous function as the first argument for setInterval, you can define it outside of setAlarm, name it something like decrementAndRenderTimer, and pass it to setInterval.

I would do that repeatedly until functions are no longer than about 4-5 lines long, and - more importantly - each function accomplishes one specific thing that can be described with the function name.

Other than that, there are a few bugs with the implementation; let me know if you are not sure how to fix those:

  • When the "Set Alarm" button is pressed multiple times while the timer is running, the timer starts showing the wrong time. This happens because setInterval is called multiple times without calling clearInterval.
  • The alarm sound plays 1 second after the timer reaches 00:00.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants