JSFiddle - React, Tailwind, and code Playground
HTML
How Old Are You?
<select class ="question" id="1howold">
<option value="three">19 - 26</option>
<option value="four">27 - 36</option>
<option value="two">37 - 40</option>
<option value="one">41+</option>
</select><br /><br />
What's Your Relationship Status?
<select class="question" id="2relationshipstatus">
<option value="four">Single and excited to see what’s out there.</option>
<option value="three">Recently single and emotionally destroyed.</option>
<option value="two">Got some casual things on the go, not looking for anything too serious.</option>
<option value="one">In a committed relationship and only taking this quiz for the lols.</option>
</select><br /><br />
Where Is Your Location?
<select class="question" id="3location">
<option value="four">Location Independent</option>
<option value="three">London/The UK</option>
<option value="two">Europe</option>
<option value="one">Elsewhere</option>
</select><br /><br />
<button type="button" onclick="finalScore(true)">Submit</button>
<div id="scoreDisplay">score goes here</div>
JavaScript
function finalScore(round) {
var correct = 0;
var selectValue;
var questions = document.getElementsByClassName("question");
var numOfQuestions = questions.length;
for (var i = 0; i < questions.length; i++) { //begin for loop
//get the value of the select element
selectValue = questions[i].options[questions[i].selectedIndex].value;
//if the value equals right
if (selectValue === "one") { //begin if then
//increment the correct variable
correct = correct + 1;
} else if (selectValue === "two") {
correct = correct + 2;
} else if (selectValue === "three") {
correct = correct + 3;
} else if (selectValue === "four") {
correct = correct + 4;
}
} //end for loop
alert(correct);
if (round === false) {
//get the percentage of correct answers(not rounded)
document.getElementById("scoreDisplay").innerHTML = correct;
} else {
//display the rounded value
document.getElementById("scoreDisplay").innerHTML = correct;
} //end if then else
} //end function