-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 839 Bytes
/
index.js
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
#!/usr/bin/env node
const inquirer = require('inquirer')
function calculate () {
inquirer
.prompt([
{
type: 'list',
name: 'timeSignature',
message: 'Choose a time signature.',
choices: ['4/4', '3/4', '2/4']
},
{
name: 'bpm',
message: 'Enter the BPM.'
},
{
name: 'bars',
message: 'Enter the number of bars.'
}
])
.then(answers => {
const beats = parseInt(answers.timeSignature)
const length = 60 / answers.bpm * beats * answers.bars
if (isNaN(length)) {
console.log('Enter integer values. (Except for a time signature)')
} else {
const min = Math.floor(length / 60)
const sec = Math.ceil(length % 60)
console.log(`${min} min ${sec} sec`)
}
})
}
calculate()