1function candidateNames() {
2 var inputs = document.getElementsByTagName("input");
3 var result = [];
4 for ( var i = 0; i < inputs.length; i += 1 ) {
5 result[i] = inputs[i].value;
6
7 if (inputs[i].value == '') { // check if value is empty
8 alert('Need to fill inputs');
9 return; // stop the function
10 }
11
12}
13 document.getElementById("candidateName1").innerHTML = result[0];
14 document.getElementById("candidateName2").innerHTML = result[1];
15 document.getElementById("candidateName3").innerHTML = result[2];
16}
17
18//Event listener to calculate button to call all above functions
19document.getElementById("btn").addEventListener("click", calculateVotes, false);
20
21function calculateVotes() {
22 candidateNames();
23}