Skip to content

ITP_London | Maryna Romanova | Module_Data_Groups | Sprint-3 | AlarmClock #500

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
function setAlarm() {}
const textArea = document.querySelector("#alarmSet");
const timeRemaining = document.querySelector("#timeValue");
const startButton = document.querySelector("#set");
let isAudioPlay = false;
let intervalId = null;

textArea.addEventListener('input', function () {
const value = textArea.value;
timeRemaining.innerHTML = value;
});

function setAlarm() {
let firstReminder = +timeRemaining.innerHTML * 1000;

if (intervalId) {
Copy link

Choose a reason for hiding this comment

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

This if statement does not seem complete

clearInterval(intervalId);
}

intervalId = setInterval(() => {
firstReminder -= 100;
Copy link

Choose a reason for hiding this comment

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

Isn't this to be 1000


if (firstReminder <= 0) {
clearInterval(intervalId);
intervalId = null;
timeRemaining.innerHTML = 0;
if (!isAudioPlay) {
playAlarm();
isAudioPlay = true;
}
} else {

timeRemaining.innerHTML = (firstReminder / 1000).toFixed(1);
}
}, 100);
}

function pauseAlarm() {
Copy link

Choose a reason for hiding this comment

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

Shouldn't the code refer to the button (listener) that makes pauseAlarm to happen?

audio.pause();
audio.currentTime = 0;
isAudioPlay = false;

if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
}

// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");

function setup() {
document.getElementById("set").addEventListener("click", () => {
console.log("1")
setAlarm();
});

Expand All @@ -18,8 +64,8 @@ function playAlarm() {
audio.play();
}

function pauseAlarm() {
audio.pause();
}
// function pauseAlarm() {
// audio.pause();
// }

window.onload = setup;
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<h1 id="timeRemaining">Time Remaining:</h1> <h1 id="timeValue"> 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />

Expand Down
20 changes: 20 additions & 0 deletions Sprint-3/alarmclock/indextime.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
</head>
<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining:</h1> <h1 id="timeValue"> 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="test.js"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions Sprint-3/alarmclock/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// const endDate = new Date("2025-03-12T03:25:00")

// console.log (endDate)
// function countDoun (){
// let now = new Date()
// console.log (now)
// if (now.getTime() < endDate.getTime()){
// //loop
// setInterval(() => {
// now = new Date()
// let timeRemide = endDate - now

// console.log (new Date (timeRemide))
// console.log (new Date(now.getTime() + timeRemide * 24 * 60 * 60 * 1000))
// console.log (new Date(daysRemaining * 24 * 60 * 60 * 1000));
// }, 1000);

// }
// else {
// console.log("finish")
// }
// }
// countDoun ()


// //new Date(now.getTime() + daysRemaining * 24 * 60 * 60 * 1000);


// //new Date(daysRemaining * 24 * 60 * 60 * 1000);