3

我正在创建一个 Simon Says 游戏,其中随着用户获得正确的模式,模式会逐渐变长,但输入历史显示他们之前的模式输入。如何清除此历史记录?

此代码位于 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();,但它什么也没做。

4

1 回答 1

0

您可以执行一个自定义函数来输出 ANSI 转义字符:

const clearTerminal = () => process.stdout.write('\033c')

(请注意,应该有更好的方法来处理您的程序,这个辅助函数只会清除您的整个窗口,这可能不是您想要的)

于 2019-05-22T16:01:19.473 回答