"use strict";

/* eslint-disable no-await-in-loop */

/* eslint-disable implicit-arrow-linebreak */
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

const question = qn => new Promise(res => {
  rl.question(qn, ans => res(ans));
});

async function main(qn) {
  let answer;

  while (!['n', 'y'].includes(answer)) {
    answer = (await question(qn)).toLowerCase();
  }

  return answer;
}

module.exports = {
  question: main,
  rl
};