I'm currently working on a project where I need to compile the answers selected in a quiz into a document.
However, I've encountered a roadblock when certain questions are skipped based on previous responses. This leads to an error message:
Uncaught TypeError: Cannot read properties of null (reading 'getAttribute')
I'm seeking guidance on how to modify my code so that it assigns a value of "N/A" when a question is skipped. Below is my attempted solution, but it hasn't worked as expected:
var oldValue = document.querySelector(".quiz_selected_answer input[name='question-2']").getAttribute('data-value');
var newValue;
if (!oldValue) {
newValue =
"N/A";
} else {
newValue = oldValue;
}
Any assistance from the community would be greatly appreciated. Thank you for your help.