ToCode Solution: תרגיל סיכום - משחק תפוס תאדום#3
ToCode Solution: תרגיל סיכום - משחק תפוס תאדום#3shlomitha wants to merge 6 commits intoynonp:masterfrom shlomitha:19-catch-red-lab
Conversation
19-catch-red-lab/game.js
Outdated
| } | ||
| scoreTxt.innerText='Score: '+ score; | ||
| redSquare.classList.remove("winner"); | ||
| redIndex=randIndex(0, 4, redIndex); |
There was a problem hiding this comment.
Since you already have allEl, better to use allEl.length instead of a hardcoded 4
There was a problem hiding this comment.
Fantastic work and on time 👍
One bonus task (if you have time/will) is to add a timer, so if a user doesn't click within 2 seconds she loses points. You can use setTimeout for the timer
Take some time to review comments I left on previous exercises and move on to lesson 20. I'll send a detailed weekly plan by mail.
|
|
||
| function chatchTheRed(ev){ | ||
| var scoreToAdd=0; | ||
| if(!ev.target.nodeName=="DIV") |
There was a problem hiding this comment.
I suggest to read the first answer here (re. == vs. === in JS):
http://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons
| redSquare=document.querySelector('.winner'); | ||
| redSquare.classList.remove("winner"); | ||
| redIndex=randIndex(0, allEl.length, redIndex); | ||
| allEl[Number(redIndex)].classList.add("winner"); |
There was a problem hiding this comment.
No need for Number(...) in array index. It happens automatically so this is just as good:
allEl[redIndex].classList.add('winner')
No description provided.