JS operates a simple exam grading system for Radiobuttons.

Yesterday and the day before, CG and I took a simple break and adjustment, feeling great. Today, I'm reporting to everyone in the afternoon to check emails. It's about a JS problem, and the problem is roughly as follows:

A cognitive style test with N questions, each with 4 options. Option A corresponds to 0 points, B corresponds to 1 point, and so on. After clicking on the grading button, it can display which style the user belongs to based on the score. For example, 0-10 points belong to Style A, 10-20 points belong to Style B.

Solution: Group four Radiobuttons together, then iterate through each group of Radiobuttons, get the selected value, and add points based on the value. If none of the options in a group are selected, display an error message.

JS code is as follows:

var score; // define score
var rate = new Array(); // define score array
// define question array, each group of questions is an array element
var question = new Array("",
// add points
function add(grade){
score += rate[grade];
// output
function output(){
if(score>=0 && score<=4)
alert("First style");
else if(score >4 && score <=8)
alert("second style");
else if(score >8 && score <=12)
alert("third style");
// get value of radio button
function getRadioValue(radioName){
var obj=document.getElementsByName(radioName);
for(var i=0;i<obj.length;i++){
return obj[i].value;

Demo link:

Tomorrow, work will start again. I wish everyone a happy Labor Day holiday.

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.