Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

NW6| Nazanin-Saedi | Module-JS2 | Alarmclock | Week-3#205

Open
nazaninsaedi wants to merge 3 commits intoCodeYourFuture:mainfrom
nazaninsaedi:alarmclockNS
Open

NW6| Nazanin-Saedi | Module-JS2 | Alarmclock | Week-3#205
nazaninsaedi wants to merge 3 commits intoCodeYourFuture:mainfrom
nazaninsaedi:alarmclockNS

Conversation

@nazaninsaedi
Copy link

No description provided.

@netlify
Copy link

netlify bot commented Jan 20, 2024

Deploy Preview for cute-gaufre-e4b4e5 ready!

Name Link
🔨 Latest commit c43a1e3
🔍 Latest deploy log https://app.netlify.com/sites/cute-gaufre-e4b4e5/deploys/65abb5010dfcc500085ef8a1
😎 Deploy Preview https://deploy-preview-205--cute-gaufre-e4b4e5.netlify.app/week-3/alarmclock
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@Ara225 Ara225 left a comment

Choose a reason for hiding this comment

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

The code here is quite good, however there is quite a big bug - when you add the alarm, the seconds are the seconds you set minus one and the seconds go down to -1 before the alarm rings. You've also changed the tests which is never a good idea in this sort of situation - they're the benchmark for your work. If you do have time, go back and sort this or we can walk through it together.

const input = document.getElementById("alarmSet");
const heading = document.getElementById("timeRemaining");

let timeInSeconds = parseInt(input.value, 10);
Copy link

Choose a reason for hiding this comment

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

The parseInt function doesn't need the second param to be specfied for this use case - have a look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt to find out why


if (isNaN(timeInSeconds) || timeInSeconds <= 0) {
alert("Please enter a valid positive number for the alarm time.");
return;
Copy link

Choose a reason for hiding this comment

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

Good touch

let seconds = timeInSeconds % 60;

countdown = setInterval(() => {
seconds--;
Copy link

Choose a reason for hiding this comment

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

This line causes a bug - the seconds go down to -1 and when you add an alarm, the time is the time you entered -1. Can you see why this happens?

if (minutes === 0) {
clearInterval(countdown);
playAlarm();
document.body.style.backgroundColor = "red"; // This was just optional, background color will change
Copy link

Choose a reason for hiding this comment

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

Nice :)


heading.innerText = `Time Remaining: ${minutes
.toString()
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
Copy link

Choose a reason for hiding this comment

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

Nice


function setup() {
document.getElementById("set").addEventListener("click", () => {
clearInterval(countdown); // Clear the previous countdown interval
Copy link

Choose a reason for hiding this comment

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

👍

document.getElementById("stop").addEventListener("click", () => {
clearInterval(countdown);
pauseAlarm();
document.getElementById("timeRemaining").innerText = "Time Remaining: 00:00";
Copy link

Choose a reason for hiding this comment

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

👍


expect(mockPlayAlarm).toHaveBeenCalledTimes(1);
});
expect(heading).toHaveTextContent("Time Remaining: 01:58");});
Copy link

Choose a reason for hiding this comment

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

You shouldn't change tests to make your code pass them - tests are there to tell you when things are wrong so you can fix them.


<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alert</button>
<audio id="alarmAudio" src="alarmsound.mp3"></audio>
Copy link

Choose a reason for hiding this comment

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

Looks good

}

.container-title {
color: #ece163;
Copy link

Choose a reason for hiding this comment

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

All CSS looking good

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.

2 participants