2 回答

TA贡献1786条经验 获得超13个赞
您可以使用数组作为FIFO数据结构(在这里我称之为队列)。
通过使用.shift(),您可以弹出集合中的第一个元素以进行打印,然后继续执行直到集合为空。(您将需要处理尝试弹出一个空对象的情况)。
var hola = false;
var plus = 0;
var wordsQueue = ['hola', 'como', 'esta']
function draw() {
class mouse {
click() {
if (mouseIsPressed) {
plus = plus + 1
}
}
}
if (mouseIsPressed) {
textSize(50);
alert(wordsQueue.shift()); //removes head of queue
}
}

TA贡献1825条经验 获得超6个赞
只需用于plus访问数组中的每个元素:
var plus = 0;
var words = ['hola', 'como', 'esta'];
document.body.addEventListener("click", () => {
plus++;
document.write(words[plus % words.length]);
});
body {
height: 100vh;
width: 100vw;
}
<body></body>
添加回答
举报