-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer1.js
More file actions
27 lines (20 loc) · 694 Bytes
/
timer1.js
File metadata and controls
27 lines (20 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const { exec } = require('child_process');
const beep = () => {
exec("[console]::beep(1000, 500)", { shell: 'powershell.exe' });
};
const alarm = (times) => {
if (!Array.isArray(times)) {
times = [times]; // This line convert a single number to an array
}
times.sort((a, b) => a - b); //This line sorts the numbers from smallest to largest
times.forEach((time) => { //This line checks each item of time to check if it is a number
if (typeof time !== 'number') {
console.log(`Not a number`);
return;
}
setTimeout(() => {//This line sets the timeout depending on the time selected multiplied by 1000
beep();
}, time * 1000);
});
};
alarm()