javascript - 节点脚本类型错误:无法读取未定义的属性“作者”
问题描述
我试图编写代码来构建测验应用程序。但我在这里面临错误。由于我是编码新手,因此无法详细说明问题。我想请您在您的系统中运行此代码。并建议我合适的答案。我在这部分发现错误let userAnswer = read.keyInSelect(choice, question);
还说:
ReferenceError: readlineSync is not defined at quiz (/home/runner/AssignmentQuiz/index.js:39:20) at /home/runner/AssignmentQuiz/index.js:57:1 at Script.runInContext (vm.js:130:18) at Object.<anonymous> (/run_dir/interp.js:209:20) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47Hint: hit control+c anytime to enter REPL.
这是代码,
const read = require('readline-sync');
const chalk = require('chalk');
const print = console.log;
//Get Name from User
let usrName = read.question(chalk.bgCyanBright.black(' Enter your name : \t'));
print("\n\n");
print(chalk.bgRed.white.bold(`\t\t\t\t\t\t Welcome ${usrName} to The Quiz Game!!! \n`));
print("\n");
//Printint Game Rules
print(chalk.underline.green.bold("Rules:\n"));
print(chalk.bgGreen.black.bold(" 1. ") + (" You Should Be Older Than 13+."));
print(chalk.bgGreen.black.bold(" 2. ") + (" It\'s Compulsory You Have To Attedend Every Question."));
print(chalk.bgGreen.black.bold(" 3. ") + (" Each Question Carries 5 Marks."));
print(chalk.bgGreen.black.bold(" 4. ") + (" On Every Wrong Question 2 Marks Will Be Deducted."));
print(chalk.bgGreen.black.bold(" 5. ") + (" You Will Atleast Get 4 Options To Choose Answer From."));
print(chalk.bgGreen.black.bold(" 6. ") + (" You Will Get Only 1 Attempt To Give Right Answer."));
//Get Age from User
print("\n");
let usrAge = read.question(chalk.bgCyanBright.black(` Hey ${usrName} how old are you : \t\t`));
print("\n\n");
let score = 0;
let rightAnswer=0;
let mcq = [
{
choice: chalk.red['query', 'programming', 'spoken', 'scripting'],
question: '1. javascript is called _____________ language? \nAnswer: ',
answer: 'scripting',
},
{
choice: chalk.red['yes', 'no', 'may be', 'not sure'],
question: '2. Do Java and JavaScript the same language? \nAnswer: ',
answer: 'no',
},
{
choice: chalk.red['c', 'python', 'swift', 'java'],
question: '3. Name \'JavaScript\' is inspired by _____________________ language? \nAnswer: ',
answer: 'java',
},
{
choice: chalk.red['plus plus', 'modulus', 'increment', 'decrement'],
question: '4. \'++\'is ______________________ operator called? \nAnswer: ',
answer: 'increment',
},
{
choice: chalk.red['client', 'server', 'front-end', 'backend'],
question: '5. \'JavaScript\' is also known as _____________-side scripting language? \nAnswer: ',
answer: 'client',
}
];
function check(choice, question, answer) {
let userAnswer = read.keyInSelect(choice, question);
print('\n');
if (choice[userAnswer] === answer) {
print(`${usrName} your answer is correct !`);
score += 5;
rightAnswer++;
}
else {
print(`Wrong answer! ${usrName}`);
print(`Right answer is: ${answer}`);
score -= 2;
}
}
for(let i = 0;i < mcq.length; i++){
print('\n');
check(mcq[i].choice,mcq[i].question,mcq[i].answer);
print('\n---------------------------------------------------\n');
}
if(rightAnswer>=3){
print(`Congratulations! ${usrName} you have successfully completed the quiz.`);
print(`Your score is : ${score}`);
}
else{
print('You have lost!');
}
解决方案
推荐阅读
- c# - 在现有的 ASP.NET MVC 页面中嵌入另一个 html 页面
- python - 对不同数据框中两列的值的首次出现求和
- fastlane - 无法使用 fastlane 将变更日志上传到 TestFlight
- cdi - 类型 javax.ws.rs.sse.Sse 和限定符 [@Default] 的 Quarkus 不满足依赖性
- javascript - document.getElementById('#symbol').onchange 没有触发 - 不知道为什么?
- sockets - 如何处理标准输入套接字上的请求?
- javascript - jquery隐藏一个id数组
- iis - SharePoint 远程事件接收器中的 DateTime 字段值与用户输入的不同
- php - 如何更新 MongoDB PHP 扩展
- amazon-web-services - 使用 powershell 对 AWS EC2 的 ssh 登录失败进行故障排除