Forum Moderators: open
}else if(questionType == 'hs') { SyntaxError: missing ; before statement
function checkAnswer(questionType,questionNumber,chosenAnswer) {
if(questionType == 'mc'){
var correct = eval('"correct' + questionNumber + '"');//Get the correct answer using the questionNumber variable.
var correctAnswer = document.getElementById(correct).value; //pull the correct answer value from the hidden input for this question
if (chosenAnswer == correctAnswer) {//Compare the checked value against the correct answer,
str = "<span class='yes'>✔</span>"; // insert the 'Heavy Checkmark'
} else {
str = "<span class='no'>✘</span>";//else insert 'Heavy Ballot X'
}
} else if(questionType == 'hs') {
var correct = eval('"hsacorrect' + questionNumber + '"');//Get the correct answer using the questionNumber variable.
var correctAnswersRaw = document.getElementById(correct.value); //pull the string of correct answers
//convert the string into an array by breaking it at the commas and pushing into an array
var correctAnswers = split.correctAnswersRaw(",");
//now have two arrays (correctAnswers and chosenAnswer). Run comparison.
for (var i=0; i < correctAnswers.length; i++){
while (i--) {
if (correctAnswers[i] === chosenAnswer) {
right.push(chosenAnswer);
}
}
}
//RIGHT array should now contain all the chosen answers that were correct.
//compare RIGHT, number of answers CHOSEN, and number of answers CORRECT
//if they match, the question is correct
if (length.right == length.chosenAnswer && length.chosenAnswer == length.correctAnswers){
str = "<span class='yes'>✔</span>"; // insert the 'Heavy Checkmark'
} else {
str = "<span class='no'>✘</span>";//else insert 'Heavy Ballot X'.
}
} else {
str = "<p>You screwed something up.</p>";
}
return str;
}
function checkAnswer(questionType, questionNumber, chosenAnswer) {
if (questionType == 'mc') {
var correct = eval('"correct' + questionNumber + '"'); //Get the correct answer using the questionNumber variable.
var correctAnswer = document.getElementById(correct).value; //pull the correct answer value from the hidden input for this question
if (chosenAnswer == correctAnswer) { //Compare the checked value against the correct answer,
str = "<span class='yes'>✔</span>"; // insert the 'Heavy Checkmark'
} else {
str = "<span class='no'>✘</span>"; //else insert 'Heavy Ballot X'
}
} else if (questionType == 'hs') {
var correct = eval('"hsacorrect' + questionNumber + '"'); //Get the correct answer using the questionNumber variable.
var correctAnswersRaw = document.getElementById(correct.value); //pull the string of correct answers
//convert the string into an array by breaking it at the commas and pushing into an array
var correctAnswers = split.correctAnswersRaw(",");
//now have two arrays (correctAnswers and chosenAnswer). Run comparison.
for (var i = 0; i < correctAnswers.length; i++) {
while (i--) {
if (correctAnswers[i] === chosenAnswer) {
right.push(chosenAnswer);
}
}
}
//RIGHT array should now contain all the chosen answers that were correct.
//compare RIGHT, number of answers CHOSEN, and number of answers CORRECT
//if they match, the question is correct
if (length.right == length.chosenAnswer && length.chosenAnswer == length.correctAnswers) {
str = "<span class='yes'>✔</span>"; // insert the 'Heavy Checkmark'
} else {
str = "<span class='no'>✘</span>"; //else insert 'Heavy Ballot X'.
}
} else {
str = "<p>You screwed something up.</p>";
}
return str;
}
First, lets format it nicely:
function checkAnswer(questionType,questionNumber,chosenAnswer)
if(questionType == 'mc')
if (chosenAnswer == correctAnswer)
else
else if(questionType == 'hs')
for (var i = 0; i < correctAnswers.length; i++)
while (i--)
if (correctAnswers[i] === chosenAnswer)
if (length.right == length.chosenAnswer && length.chosenAnswer == length.correctAnswers)
else
else
return str;
When you look at someone else's code, do you always have to reformat it before you can bear to look at it?
I can never get any of the "pre" modes to work