// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require jquery
//= require jquery_ujs


$(document).ready(function() {

	// Javascript for button validation
  $("input[type=radio]").click(function() {
    el = $(this);
    col = el.data("col");
    
    el
      .parents(".question")
      .find("input[data-col=" + col + "]")
      .prop("checked", false);
    el.prop("checked", true);
  })


// Javascript for result calculation
  $("input[type=radio]").click(function() {
    var totalCon = 0, totalCol = 0, totalCom = 0, totalCha = 0; 

	$("input[data-prop='con']:checked").each(function() {
	totalCon += parseInt($(this).val())});
	$("#totalCon").html(totalCon);
	$("#con_val").val(totalCon)

	$("input[data-prop='col']:checked").each(function() {
	totalCol += parseInt($(this).val())});
	$("#totalCol").html(totalCol);
	$("#col_val").val(totalCol)

	$("input[data-prop='com']:checked").each(function() {
	totalCom += parseInt($(this).val())});
	$("#totalCom").html(totalCom);
	$("#com_val").val(totalCom)

	$("input[data-prop='cha']:checked").each(function() {
	totalCha += parseInt($(this).val())});
	$("#totalCha").html(totalCha);
	$("#cha_val").val(totalCha)

  })


  // Javascript for submit button validation
	$( "input[type=submit]" ).click(function() {
		var question = validate_form();
		if( question == 0 ) {
		 	return;
		 }
		else {
			alert("Please finish question " + question + " before submitting!");
			event.preventDefault();
		}
	})

	// Iterates through all answers and checks that they are ranked 
	// Returns 0 if all are checked, otherwise returns first question that isn't finished
	function validate_form() {
		var check;
		for (i = 1; i < 19; i++) {
			for (j = 1; j < 5; j++) {
				check = 0;
				name = "q" + i + "a" + j;
				if ($("input[name='" + name + "']:checked").length == 0) {
					return i;
				}
			}
		}
		return 0;
	}

});
@@ -1908,16 +1908,17 @@
 question
+s
  = valid
@@ -1937,18 +1937,18 @@
 %09%09if
-(
  
+(
 question
  == 
@@ -1943,16 +1943,22 @@
 question
+s.size
  == 0 ) 
@@ -1992,50 +1992,327 @@
 %0A%09%09%09
-alert(%22Please finish question %22 + question
+questionString = %22%22;%0A%09%09%09questions.forEach(function(value) %7B%0A%09%09%09  questionString = questionString + %22, %22 + value;%0A%09%09%09%7D);%0A%09%09%09if (questions.size == 1) %7B%0A%09%09%09%09alert(%22Please finish question%22 + questionString.substring(1) + %22 before submitting!%22);%0A%0A%09%09%09%7D else %7B%0A%09%09%09%09alert(%22Please finish questions%22 + questionString.substring(1)
  + %22
@@ -2334,16 +2334,21 @@
 ing!%22);%0A
+%09%09%09%7D%0A
 %09%09%09event
@@ -2562,21 +2562,35 @@
 %7B%0A%09%09var 
-check
+numbers = new Set()
 ;%0A%09%09for 
@@ -2645,23 +2645,8 @@
 ) %7B%0A
-%09%09%09%09check = 0;%0A
 %09%09%09%09
@@ -2743,16 +2743,22 @@
 %09%09%09%09
-return i
+numbers.add(i)
 ;%0A%09%09
@@ -2779,17 +2779,23 @@
 %09return 
-0
+numbers
 ;%0A%09%7D%0A%0A%7D)

Edit confirmation so that it shows all questions not answered