@elaineleung
Posted
Hi Yaika Race, great job in completing this first JS challenge! Everything works well, and I like how you used some logic to handle what happens when nothing is selected. Great work also in displaying a warning reminder!
Two suggestions I have here:
-
Instead of using
<p>
, use an interactive element like<button>
instead, asp
is really not meant for this task (it's more of a pure text element), and buttons are more suited since they handle actions. Buttons also allow for attributes such asvalue
, and so you can store a value that you can later retrieve in the JS (e.g.,value="1"
). -
Great job using the
forEach
! I see that you also have theidx
in your function and that you later use the index for displaying the score. A simpler way that does not involve adding 1 to the index would be to just retrieve thetextContent
, or if you do use avalue
attribute in the button as I mentioned above, then you can useevent.target.value
or even just the element'svalue
. To see this in action, you can check out this mini CodePen I made for this challenge: https://codepen.io/elaineleung/pen/RwMqMxZ
Anyway, really great job on the whole in writing out all the JS here! 😊
Marked as helpful