MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / hit

Function hit

assets/js/click_shape_JS.js:63–86  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

61}
62
63function hit(e){
64 let start = e.target.start;
65 let end = new Date().getTime();
66 let duration = (end-start)/1000;
67 let maxDuration = 1;
68
69 clearTimeout(playArea.timer);
70 showMessage('It took you ' + duration + ' seconds to click');
71 if (duration > maxDuration){
72 gameArea.children[0].remove();
73 results.innerHTML = `Too Slow! <span id="loser">You Lose!</span> Your score was ${count}.<br> Click the start button to play again!`;
74 resetGame();
75 } else {
76 gameArea.children[0].remove();
77 playArea.timer = setTimeout(myBox, random(4000));
78 count++;
79 if (count === 15){
80 results.innerHTML = `You reached ${renderCount(count)}! <span id="winner">You win!</span> <br> Click start to Play again.`;
81 resetGame();
82 } else {
83 results.innerHTML = `Score: ${renderCount(count)} of 15`;
84 }
85 }
86}
87
88function renderCount(count){
89 return count;

Callers

nothing calls this directly

Calls 4

showMessageFunction · 0.70
resetGameFunction · 0.70
randomFunction · 0.70
renderCountFunction · 0.70

Tested by

no test coverage detected