Skip to content

Instantly share code, notes, and snippets.

@tebriel
Last active January 4, 2016 03:28
Show Gist options
  • Select an option

  • Save tebriel/8561654 to your computer and use it in GitHub Desktop.

Select an option

Save tebriel/8561654 to your computer and use it in GitHub Desktop.
function checkAnswer(form) {
var errorMsg = 0;
for (a = 0; a < 4; a++) {
if (form.question_1[a].checked)
break;
}
var q1 = a+1;
if (q1 == 5) {q1 = 0; errorMsg++; }
for (b = 0; b < 4; b++) {
if (form.question_2[b].checked)
break;
}
var q2 = b+1;
if (q2 == 5) {q2 = 0; errorMsg++; }
for (c = 0; c < 4; c++) {
if (form.question_3[c].checked)
break;
}
var q3 = c+1;
if (q3 == 5) {q3 = 0; errorMsg++; }
for (d = 0; d < 4; d++) {
if (form.question_4[d].checked)
break;
}
var q4 = d+1;
if (q4 == 5) {q4 = 0; errorMsg++; }
for (e = 0; e < 4; e++) {
if (form.question_5[e].checked)
break;
}
var q5 = e+1;
if (q5 == 5) {q5 = 0; errorMsg++; }
for (f = 0; f < 4; f++) {
if (form.question_6[f].checked)
break;
}
var q6 = f+1;
if (q6 == 5) {q6 = 0; errorMsg++; }
for (g = 0; g < 4; g++) {
if (form.question_7[g].checked)
break;
}
var q7 = g+1;
if (q7 == 5) {q7 = 0; errorMsg++; }
for (h = 0; h < 4; h++) {
if (form.question_8[h].checked)
break;
}
var q8 = h+1;
if (q8 == 5) {q8 = 0; errorMsg++; }
for (i = 0; i < 4; i++) {
if (form.question_9[i].checked)
break;
}
var q9 = i+1;
if (q9 == 5) {q9 = 0; errorMsg++; }
for (j = 0; j < 4; j++) {
if (form.question_10[j].checked)
break;
}
var q10 = j+1;
if (q10 == 5) {q10 = 0; errorMsg++; }
for (k = 0; k < 4; k++) {
if (form.question_11[k].checked)
break;
}
var q11 = k+1;
if (q11 == 5) {q11 = 0; errorMsg++; }
for (l = 0; l < 4; l++) {
if (form.question_12[l].checked)
break;
}
var q12 = l+1;
if (q12 == 5) {q12 = 0; errorMsg++; }
for (m = 0; m < 4; m++) {
if (form.question_13[m].checked)
break;
}
var q13 = m+1;
if (q13 == 5) {q13 = 0; errorMsg++; }
for (n = 0; n < 4; n++) {
if (form.question_14[n].checked)
break;
}
var q14 = n+1;
if (q14 == 5) {q14 = 0; errorMsg++; }
for (o = 0; o < 4; o++) {
if (form.question_15[o].checked)
break;
}
var q15 = o+1;
if (q15 == 5) {q15 = 0; errorMsg++; }
for (p = 0; p < 4; p++) {
if (form.question_16[p].checked)
break;
}
var q16 = p+1;
if (q16 == 5) {q16 = 0; errorMsg++; }
for (q = 0; q < 4; q++) {
if (form.question_17[q].checked)
break;
}
var q17 = q+1;
if (q17 == 5) {q17 = 0; errorMsg++; }
for (r = 0; r < 4; r++) {
if (form.question_18[r].checked)
break;
}
var q18 = r+1;
if (q18 == 5) {q18 = 0; errorMsg++; }
for (s = 0; s < 4; s++) {
if (form.question_19[s].checked)
break;
}
var q19 = s+1;
if (q19 == 5) {q19 = 0; errorMsg++; }
for (t = 0; t < 4; t++) {
if (form.question_20[t].checked)
break;
}
var q20 = t+1;
if (q20 == 5) {q20 = 0; errorMsg++; }
for (v = 0; v < 4; v++) {
if (form.question_21[v].checked)
break;
}
var q21 = v+1;
if (q21 == 5) {q21 = 0; errorMsg++; }
for (w = 0; w < 4; w++) {
if (form.question_22[w].checked)
break;
}
var q22 = w+1;
if (q22 == 5) {q22 = 0; errorMsg++; }
for (x = 0; x < 4; x++) {
if (form.question_23[x].checked)
break;
}
var q23 = x+1;
if (q23 == 5) {q23 = 0; errorMsg++; }
for (y = 0; y < 4; y++) {
if (form.question_24[y].checked)
break;
}
var q24 = y+1;
if (q24 == 5) {q24 = 0; errorMsg++; }
for (z = 0; z < 4; z++) {
if (form.question_25[z].checked)
break;
}
var q25 = z+1;
if (q25 == 5) {q25 = 0; errorMsg++; }
var total = q1+q2+q3+q4+q5+q6+q7+q8+q9+q10+q11+q12+q13+q14+q15+q16+q17+q18+q19+q20+q21+q22+q23+q24+q25;
showResults(total,errorMsg);
return false;
}
function checkAnswer(form) {
var missedQuestions = 0;
var totalScore = 0;
for (var questionId=1; questionId<=25; questionId++) {
var idx = 0;
for (idx = 0; idx < 4; idx++) {
if (form['question_'+questionId][idx].checked)
break;
}
if (idx === 4) {
idx = 0;
missedQuestions++;
}
totalScore += idx;
idx = 0;
}
showResults(totalScore,missedQuestions);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment