let level_of_education_points=0;
let speaking_points=0;
let writing_points=0;
let reading_points=0;
let listening_points=0;
let second_official_language_points=0;
let applicant_work_experience_points=0;
let age_of_applicant_points=0;
let arranged_employment_points=0;
let adaptability_points=0;

$(document).ready(function(){

  $('.level_of_education').click(function(){
    level_of_education_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints2();
  });

  $('.speaking').click(function(){
    speaking_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;  
    showPoints2();
   });

$('.writing').click(function(){
    writing_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0; 
    showPoints2();
  });
   
$('.reading').click(function(){
    reading_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints2();
 });

 $('.listening').click(function(){
    listening_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints2();
 });

$('.second_official_language').click(function(){
    second_official_language_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints2();
   });

$('.applicant_work_experience').click(function(){
    applicant_work_experience_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints2();
   });

$('.age_of_applicant').change(function(){
    age_of_applicant_points = parseInt($(this).val());
    showPoints2();
   });

$('.arranged_employment').click(function(){
    arranged_employment_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints2();
   });
 
$('.adaptability').click(function(){
    adaptability_points = 0;
    var input = document.getElementsByName("adaptability[]");  
    for(var i=0;i<input.length;i++) {
    if(input[i].checked){ 
        adaptability_points += parseInt(input[i].value);
    }}
    adaptability_points = (adaptability_points > 10) ? 10 : adaptability_points;
    showPoints2();
   }); 
});

showPoints2 = ()=>{
 let final_points=0;
 final_points = level_of_education_points+speaking_points+writing_points+reading_points+listening_points+second_official_language_points+applicant_work_experience_points+age_of_applicant_points+arranged_employment_points+adaptability_points;   
 $('.final_points').val(final_points);
}