MCPcopy Create free account
hub / github.com/SuperSimpleDev/javascript-course / autoPlay

Function autoPlay

1-exercise-solutions/lesson-12/12t.js:2–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1// See 12r.js for the full code.
2function autoPlay() {
3 if (!isAutoPlaying) {
4 intervalId = setInterval(() => {
5 const playerMove = pickComputerMove();
6 playGame(playerMove);
7 }, 1000);
8 isAutoPlaying = true;
9
10 // When the game is auto playing, change
11 // the text in the button to 'Stop Playing'.
12 document.querySelector('.js-auto-play-button')
13 .innerHTML = 'Stop Playing';
14
15 } else {
16 clearInterval(intervalId);
17 isAutoPlaying = false;
18
19 // When the game is not playing, change
20 // the text back to 'Auto Play'.
21 document.querySelector('.js-auto-play-button')
22 .innerHTML = 'Auto Play';
23 }
24}

Callers

nothing calls this directly

Calls 4

pickComputerMoveFunction · 0.70
playGameFunction · 0.70
setIntervalFunction · 0.50
clearIntervalFunction · 0.50

Tested by

no test coverage detected