-
Notifications
You must be signed in to change notification settings - Fork 0
/
10index.ts
50 lines (38 loc) · 1.46 KB
/
10index.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
import chalkAnimation from "chalk-animation";
const userInput = await inquirer.prompt([
{
type: "number",
name: "minutes",
message: "Enter minutes in number"
},
{
type: "number",
name: "seconds",
message: "Enter seconds in number"
}
])
if (isNaN(userInput.minutes) || isNaN(userInput.seconds)){
console.log("please insert valid number")
}
async function Timer(minutes:number , seconds: number) {
console.log(`TIME INSERT = ${minutes} minutes and ${seconds} seconds`)
const totalSeconds = minutes * 60 + seconds;
let remainingSeconds = totalSeconds;
// create a setInterval function to start timer
const timerInterval = setInterval(() => {
const minutesRemaining = Math.floor(remainingSeconds / 60);
const secondsRemaining = remainingSeconds % 60;
console.log(`Time Remaining: ${minutesRemaining} minutes ${secondsRemaining} seconds`);
remainingSeconds--;
// create clearIntervel function to stop the setIntervel Functions
if (remainingSeconds < 0) {
clearInterval(timerInterval);
console.log("Timer's up!");
console.log(chalk.bgGreenBright`Developed by Rubab Nasir`);
}
}, 1000);
}
Timer(userInput.minutes, userInput.seconds)