-
-
Notifications
You must be signed in to change notification settings - Fork 147
Sheffield|May-2025|Sheida Shabankari|Module-Data -Groups| Sprint-3|Alarm Clock #631
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
base: main
Are you sure you want to change the base?
Changes from all commits
abdcbfd
3e2debe
32f9d24
55f13a4
a674f0b
e2eb3bb
244219b
8d01d83
35c72e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,98 @@ | ||
function setAlarm() {} | ||
var flashColor; | ||
function setAlarm() { | ||
const userInput=document.getElementById("alarmSet"); | ||
|
||
let inputTime=userInput.value; | ||
if (inputTime <= 0 || isNaN(inputTime)) { | ||
alert("invalid input!!!"); | ||
return; | ||
} | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some unusual input values that can make your app behave abnormally can still pass this check. Can you add code to sanitise them? |
||
updateDisplayTime(inputTime); | ||
let secondsInterval=setInterval(() => { | ||
inputTime--; | ||
updateDisplayTime(inputTime); | ||
if ((inputTime === 0)) { | ||
playAlarm(); | ||
clearInterval(secondsInterval); | ||
|
||
} | ||
}, 1000); | ||
|
||
} | ||
|
||
|
||
|
||
function updateDisplayTime(inputTime){ | ||
const timeRemain = document.getElementById("timeRemaining"); | ||
let min = String(Math.floor(inputTime / 60)).padStart(2, "0"); | ||
let sec = String(inputTime % 60).padStart(2, "0"); | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can consider declaring these two variables with |
||
timeRemain.textContent = `Time Remaining: ${min}:${sec}`; | ||
} | ||
// DO NOT EDIT BELOW HERE | ||
|
||
var audio = new Audio("alarmsound.mp3"); | ||
|
||
function setup() { | ||
document.getElementById("set").addEventListener("click", () => { | ||
setAlarm(); | ||
}); | ||
|
||
document.getElementById("stop").addEventListener("click", () => { | ||
pauseAlarm(); | ||
|
||
}); | ||
} | ||
|
||
function playAlarm() { | ||
audio.play(); | ||
document.getElementById("stop").style.backgroundColor = "rgb(191, 115, 47)"; | ||
document.body.style.backgroundColor = "rgb(218, 178, 119)"; | ||
let flashColor=setInterval(() => { | ||
if(document.body.style.backgroundColor === "rgb(218, 178, 119)"){ | ||
document.body.style.backgroundColor = "white"; | ||
}else{ | ||
document.body.style.backgroundColor = "rgb(218, 178, 119)"; | ||
Comment on lines
+48
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could consider preparing several CSS classes in a CSS file and then assign/remove CSS class to these element to change their appearance. This way, if we want to change the styles (including color), we don't have to modify the JS code. |
||
} | ||
|
||
}, 500); | ||
} | ||
|
||
function pauseAlarm() { | ||
audio.pause(); | ||
document.getElementById("stop").style.backgroundColor = "rgb(239, 239, 239)"; | ||
clearInterval(flashColor); | ||
document.body.style.backgroundColor = "white"; | ||
} | ||
|
||
window.onload = setup;function setAlarm() { | ||
const userInput=document.getElementById("alarmSet"); | ||
|
||
let inputTime=userInput.value; | ||
if (inputTime <= 0 || isNaN(inputTime)) { | ||
alert("invalid input!!!"); | ||
return; | ||
} | ||
updateDisplayTime(inputTime); | ||
let secondsInterval=setInterval(() => { | ||
inputTime--; | ||
updateDisplayTime(inputTime); | ||
if ((inputTime === 0)) { | ||
playAlarm(); | ||
clearInterval(secondsInterval); | ||
|
||
} | ||
}, 1000); | ||
|
||
} | ||
|
||
|
||
|
||
function updateDisplayTime(inputTime){ | ||
const timeRemain = document.getElementById("timeRemaining"); | ||
let min = String(Math.floor(inputTime / 60)).padStart(2, "0"); | ||
let sec = String(inputTime % 60).padStart(2, "0"); | ||
timeRemain.textContent = `Time Remaining: ${min}:${sec}`; | ||
} | ||
// DO NOT EDIT BELOW HERE | ||
|
||
var audio = new Audio("alarmsound.mp3"); | ||
|
@@ -11,15 +104,29 @@ function setup() { | |
|
||
document.getElementById("stop").addEventListener("click", () => { | ||
pauseAlarm(); | ||
|
||
}); | ||
} | ||
|
||
function playAlarm() { | ||
audio.play(); | ||
document.getElementById("stop").style.backgroundColor = "rgb(191, 115, 47)"; | ||
document.body.style.backgroundColor = "rgb(218, 178, 119)"; | ||
flashColor=setInterval(() => { | ||
if(document.body.style.backgroundColor === "rgb(218, 178, 119)"){ | ||
document.body.style.backgroundColor = "white"; | ||
}else{ | ||
document.body.style.backgroundColor = "rgb(218, 178, 119)"; | ||
} | ||
|
||
}, 500); | ||
} | ||
|
||
function pauseAlarm() { | ||
audio.pause(); | ||
document.getElementById("stop").style.backgroundColor = "rgb(239, 239, 239)"; | ||
clearInterval(flashColor); | ||
document.body.style.backgroundColor = "white"; | ||
} | ||
|
||
window.onload = setup; |
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.
Why use
var
instead oflet
?