有没有办法仅使用 JavaScript 来操纵控制台.log输出和下一个用户输入提示之间的时间

Is there a way to manipulate the timing between console.log output and the next userInput prompt using only JavaScript?

本文关键字:用户 下一个 输出 输入 提示 时间 之间 log 控制台 操纵 JavaScript      更新时间:2023-09-26

>我正在学习JS。我正在玩一个标准的,易于练习的JS"游戏",例如"选择自己的冒险"。我正在使用基本的"if/else"语句,我希望它输出:

'{Prompt/getUserInput} first --

然后是 {console.log}, 然后 {prompt}, 然后是 {console.log}, 等等。

但是,当我将代码放入 repl.it 时,我得到{提示}{提示}{提示},然后是所有控制台日志。 - 这里有一个片段,所以你可以明白我的意思:

var buffer = function(){
console.log("------------------");
}
console.log("You are alone in the woods...");
buffer()
var userInput = prompt("You can either walk further into the woods or    turn around. Please enter 'go on' or 'screw this'");
if(userInput === "go on"){ 
console.log("It is getting darker and darker. By the time you hear his heavy breathing behind you, it is too late");
}
if (userInput === "screw this"){
console.log("You always knew you were the only person in the village with a lick of sense. Now, where did you hide those bodies...");
}
buffer();

有没有办法让它阅读更多的 A.B.A.B 而不是 AAA。BBB?

你的代码很好。repl.it 实现应该有一些错误如果您在浏览器中打开控制台(对于 chrome 是 ctrl+shift+j | cmd+opt+j,对于 firefox ctrl+shift+k | cmd+opt+k(,然后粘贴您的代码并按 Enter 即可工作