I know it's the weekend but I remembered I forgot to show you an easier way to grab all the inputs from a submit event.
You can use event.target.elements to get an HTMLFormControlsCollection, which contains all the inputs submitted in the form. This also conveniently has the group of radio buttons under a key matching the name you set on the radios. So in your case event.target.elements.description gets you a RadioNodeList of your four radio inputs. You can get the selected value of the radio group with event.elements.description.value.
So you can replace the whole form.map... thing with const answer = event.elements.description.value 😁
One thing I would note is that it's more common (and often a lot simpler) to use "controlled components" to keep all your form state in JavaScript (rather than having to awkwardly get it from the DOM). The final section of Monday's workshop has more info on it
I know it's the weekend but I remembered I forgot to show you an easier way to grab all the inputs from a submit event.
You can use
event.target.elementsto get anHTMLFormControlsCollection, which contains all the inputs submitted in the form. This also conveniently has the group of radio buttons under a key matching thenameyou set on the radios. So in your caseevent.target.elements.descriptiongets you aRadioNodeListof your four radio inputs. You can get the selected value of the radio group withevent.elements.description.value.So you can replace the whole
form.map...thing withconst answer = event.elements.description.value😁One thing I would note is that it's more common (and often a lot simpler) to use "controlled components" to keep all your form state in JavaScript (rather than having to awkwardly get it from the DOM). The final section of Monday's workshop has more info on it