'use strict';

const axios = require('axios');
const cheerio = require('cheerio');
const inquirer = require('inquirer');

const baseUrl = "http://www.liburnasional.com/kalender-2017/";

var holidays = [];

axios.get(baseUrl).then(res => {
    var $ = cheerio.load(res.data);
    // get data
    $('.libnas-calendar-holiday-title').each(function(x, y) {
        holidays.push({
            day     : y.children[1].children[0].data,
            date    : y.children[2].children[0].data,
            title   : y.children[0].children[0].children[0].children[0].data,
        });
    });
    return holidays;
}).then(holidays => {
    var currentYear = new Date().getFullYear(); //get current Year
    var years       = [];
    
    // get lists years, five years from current year
    for (var i = 0; i < 5; i++) {
        var temp = currentYear+i;
        years.push(temp.toString());
    }

    return inquirer.prompt([{
        type    : "list",
        name    : "data",
        message : "Pilih Tahun: ",
        choices : years
    }]);
}).then(answer => {
    // console.log("ntak");
});

@@ -131,16 +131,78 @@
 nst 
-base
+listYears     = %22http://www.liburnasional.com/%22;%0D%0Aconst holidays
 Url 
+  
 = %22h
@@ -242,13 +242,8 @@
 der-
-2017/
 %22;%0D%0A
@@ -280,15 +280,17 @@
 get(
-baseUrl
+listYears
 ).th
@@ -347,132 +347,44 @@
     
-// get data%0D%0A    $('.libnas-calendar-holiday-title').each(function(x, y) %7B%0D%0A        holidays.push(%7B%0D%0A            day     : y
+var root = $('.dropdown-menu').eq(0)
 .chi
@@ -392,11 +392,10 @@
 dren
-%5B1%5D
+()
 .chi
@@ -403,479 +403,135 @@
 dren
-%5B0%5D.data,%0D%0A            date    : y.children%5B2%5D.children%5B0%5D.data,%0D%0A            title   : y.children%5B0%5D.children%5B0%5D.children%5B0%5D.children%5B0%5D.data,%0D%0A        %7D);%0D%0A    %7D);%0D%0A    return holidays;%0D%0A%7D).then(holidays =%3E %7B%0D%0A    var currentYear = new Date().getFullYear(); //get current Year%0D%0A    var years       = %5B%5D;%0D%0A    %0D%0A    // get lists years, five years from current year%0D%0A    for (var i = 0; i %3C 5; i++) %7B%0D%0A        var temp = currentYear+i;%0D%0A        years.push(temp.toString()
+();%0D%0A    var years = %5B%5D;%0D%0A%0D%0A    root.each(function(x, y) %7B%0D%0A        years.push(%7Bname: y.children%5B0%5D.data, link: y.attribs.href%7D
 );%0D%0A
@@ -535,16 +535,18 @@
 ;%0D%0A    %7D
+);
 %0D%0A%0D%0A    
@@ -618,20 +618,21 @@
 e    : %22
-data
+years
 %22,%0D%0A    
@@ -727,30 +727,77 @@
     
-// console.log(%22ntak%22)
+var year = answer.years.split(%22 %22);%0D%0A    return year%5Byear.length - 1%5D
 ;%0D%0A%7D

refactor processing get data