I am building an application that has some quiz questions using radio buttons (on 3 separate html pages). I have written a js function that fits all 3 html pages by bringing the page title to a variable (thisquestion). I then pull the user's radio button response (optionone, optiontwo, optionthree or optionfour) into a variable(selectedValue).
I am looking to test all possible combinations of thisquestion and selectedValue against the expected correct answers (answerFlags are simple binary variables: correct = 1, incorrect = 2)
I'm struggling with where to start! I'm new to Jasmine.
The js function is ...
//Function: check the answers against desired for each question-xxx.html //
function checkQuestionRadio() {
const rbs = document.querySelectorAll('input[name="question"]');
let selectedValue;
for (const rb of rbs) {
if (rb.checked) {
selectedValue = rb.id;
break;
}
}
// log to Console to test Functionality //
console.log(selectedValue);
let thisquestion = document.title;
// answers to radio button style questions //
switch(thisquestion) {
case 'Online Learning - Question 1':
if (selectedValue == 'optionfour') {
answerFlagOne = 1;
} else {
answerFlagOne = 0;
}
break;
case 'Online Learning - Question 3':
if (selectedValue == 'optiontwo') {
answerFlagThree = 1;
} else {
answerFlagThree = 0;
}
break;
case 'Online Learning - Question 8':
if (selectedValue == 'optionthree') {
answerFlagEight = 1;
} else {
answerFlagEight = 0;
}
break;
default:
console.log('did not work');
break;
}
// log to Console to test Functionality //
console.log('answerFlagOne: ' + answerFlagOne);
console.log('answerFlagThree: ' + answerFlagThree);
console.log('answerFlagEight: ' + answerFlagEight);
}
Aucun commentaire:
Enregistrer un commentaire