我正在创建一个西蒙游戏(Simon Says),当用户正确复制模式时,模式会逐渐变长,但输入历史记录会显示他们以前的模式输入。我应该如何清除这个历史记录?
这段代码位于CodeHS网站上。我已经尝试了console.clear();、clear();和console.API.clear(),但似乎都不起作用。
以下是我的代码部分,用于获取用户的输入。
这段代码位于CodeHS网站上。我已经尝试了console.clear();、clear();和console.API.clear(),但似乎都不起作用。
以下是我的代码部分,用于获取用户的输入。
//green red blue yellow
var generatedPattern = "grby"
function getUserInput(){
/*User input of the last round gets saved which shows them 'grb', allowing
the user to look back at their previous guess to easily guess the
next pattern*/
guess = readLine("Input guess here: (example: ybbg)");
if(guess == generatedPattern){
return true;
}else{
return false;
}
}
我希望使用clear()或console.clear()方法来清除日志,但它们没有起到任何作用。
.clear()
通常清除的是控制台,而不是输入历史记录。这通常并不由您的程序管理,而是由终端本身管理。 - BergireadLine.createInterface
(https://nodejs.org/api/readline.html#readline_readline_createinterface_options)有一个`historySize`选项。 - Bergi