NodeJS 根据用户选择尝试后藤二个查询者提示

qncylg1j  于 2022-12-22  发布在  Node.js
关注(0)|答案(1)|浏览(184)

这里是训练营学员。我正在尝试一起生成一个团队配置文件。在输入经理信息后,我可以决定是否要添加工程师、实习生或不再添加。但是,当我选择工程师选项时,应用程序应该显示另一个询问者提示以输入工程师信息。当前的代码不允许我这样做,实际上在终端上结束了这个过程。我哪里出错了?

const inquirer = require("inquirer");
const fs = require("fs");
const path = require("path");

const Engineer = require("./lib/Engineer");
const Intern = require("./lib/Intern");
const Manager = require("./lib/Manager");

const DIST_DIR = path.resolve(__dirname, "dist");
const distPath = path.join(DIST_DIR, "team.html");

const render = require("./src/renderHTML");

let teamMembers = [];
let teamIDs = [];

function startApp() {
  function addManager() {
    inquirer
      .prompt([
        {
          type: "input",
          name: "managerName",
          message: "What is the your name?",
          validate: (input) => {
            if (input) {
              return true;
            } else {
              console.log("Please enter your name to continue!");
              return false;
            }
          },
        },    (other questions here)
      ])
      .then((answers) => {
        const manager = new Manager(
          answers.managerName,
          answers.managerID,
          answers.managerEmail,
          answers.managerOffice
        );
        teamMembers.push(manager);
        teamIDs.push(answers.managerID);
        addTeamMember();
      });
  }

  function addTeamMember() {
    inquirer
      .prompt([
        {
          type: "list",
          name: "member",
          message: `Select which team member you'd like to add to your team!`,
          choices: ["Engineer", "Intern", "No team members to add"],
        },
      ])
      .then((answers) => {
        switch (answers.memberChoice) {
          case "Engineer":
            generateEng();                 <----- This is the area I'm having trouble with
            break;                      When I select Engineer, it should run generateEng()
          case "Intern":                But is instead stopping code execution, via terminal
            generateInt();
            break;
          default:
            makeTeam();
        }
      });
  }

  function generateEng() {
    inquirer
      .prompt([
        {
          type: "input",
          name: "engName",
          message: `What is the engineer's name?`,
          validate: (input) => {
            if (input) {
              return true;
            } else {
              console.log("Please enter the engineer's name to continue!");
              return false;
            }
          },
        },  (other questions here)
      ])
      .then((answers) => {
        const engineer = new Engineer(
          answers.engName,
          answers.engID,
          answers.engEmail,
          answers.engGithub
        );
        teamMembers.push(engineer);
        teamIDs.push(answers.engID);
        addTeamMember();
      });
  }

  function generateInt() {
    inquirer
      .prompt([
        {
          type: "input",
          name: "Name",
          message: `What is the intern's name?`,
          validate: (input) => {
            if (input) {
              return true;
            } else {
              console.log("Please enter the intern's name to continue!");
              return false;
            }
          },
        }, (other questions here)
      ])
      .then((answers) => {
        const intern = new Intern(
          answers.intName,
          answers.intID,
          answers.intEmail,
          answers.intGithub
        );
        teamMembers.push(intern);
        teamIDs.push(intID);
        addTeamMember();
      });
  }

  function makeTeam() {
    fs.writeFileSync(distPath, render(teamMembers), "utf-8");
  }

  addManager();
}

startApp();
w6lpcovy

w6lpcovy1#

而不是答案。memberChoice它应该是答案。member

相关问题