-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (29 loc) · 1012 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
37
import {confirm, input, select} from "@inquirer/prompts";
import * as zipcode from "zipcodes";
import {fetchBurrito, fetchListOfStores} from "./fetch-utils.js";
const askToRun = async () => {
return confirm({message: `Again?`});
}
const init = async () => {
let zip = await input({message: "Enter a Zip Code"});
zip = zipcode.lookup(zip);
const storeList = await fetchListOfStores(zip.latitude, zip.longitude);
if(storeList.length > 0) {
const selectedStore = await select({
pageSize: 10,
message: 'Select a store',
choices: storeList
});
const burrito = await fetchBurrito(selectedStore);
console.log(`The price for a 5-Layer Burrito at this store is: ${burrito}`);
} else {
console.log(`Sadly, there are no Taco Bell locations near you. Try another ZIP code.`);
}
}
(async () => {
let runAgain = true;
while(runAgain) {
await init();
runAgain = await askToRun();
}
})();