function NumClMatching_block(myWordClass, myWord, myWordTranslate, animateNounTranslate, inanimateNounTranslate, reps, testing_text, task_type) {

    // myWordClass: ['Number Word', 'Class Word']
    // myWordTranslate: [['two','three'],['animate','inanimate']]
    // exposure_text: ['exposure text for Num','exposure text for Cl']
    // reps: repetitions for each of the four words (not each word class), so repetitions for each word class is 2*reps 
	var testing_trials = [];
    var score = [];
    score[0] = 0; //number word score
    score[1] = 0; //class word score
    
    // ******* create sequence of word classes
    var seq_all_trials_in_word_class = [];
    var s = 0;    
    for (var w=0; w<myWordClass.length; w++){
        for (var r=0; r<2*reps; r++){
            seq_all_trials_in_word_class[s] = myWordClass[w];
            s+=1;
        }
    }
    // seq_all_trials_in_word_class: ['Number Word','Number Word','Number Word',...,'Number Word','Class Word','Class Word','Class Word',...,'Class Word'];
    
    var total_number_of_trials = seq_all_trials_in_word_class.length;
    // randomise sequence
	var if_consecutive_items = true;
    var max_num_consecutive_items = 2;
    while (if_consecutive_items == true){
        seq_all_trials_in_word_class = shuffle(seq_all_trials_in_word_class);
        if_consecutive_items = if_consecutive(seq_all_trials_in_word_class, max_num_consecutive_items+1);		
        // ensure that a same word class does not present more than twice consecutively
    };
    // e.g., seq_all_trials_in_word_class: ['Class Word','Number Word','Number Word','Class Word','Class Word','Number Word','Class Word','Class Word','Number Word',...];

    // ******* create sequence of words for each word class
    var seq_words_withinWordClass = [];
    for (var w=0; w<myWordClass.length; w++){
        seq_words_withinWordClass[w] = [];
        var s = 0;
        for (var v=0; v<myWordTranslate[w].length; v++){
            for (var r=0; r<reps; r++){
                seq_words_withinWordClass[w][s] = myWordTranslate[w][v];
                s+=1;
            }
        }
    }
    
    // seq_words_withinWordClass: [['two','two',...,'two',..,'three','three',...,'three'],['animate','animate',...,'animate','inanimate','inanimate',...,'inanimate']]
    // shuffle this sequence
    var max_num_consecutive_items = 2;
    for (var w=0; w<myWordClass.length; w++){
        var if_consecutive_items = true;
        while (if_consecutive_items == true){
            seq_words_withinWordClass[w] = shuffle(seq_words_withinWordClass[w]);
            if_consecutive_items = if_consecutive(seq_words_withinWordClass[w], max_num_consecutive_items+1);		
            // ensure that a same word does not present more than twice consecutively within a word class
        }
    };

    // ******* initiate trial number for each word class
    var trl_num_currWrdClss = [];
    for (var w=0; w<myWordClass.length; w++){
        trl_num_currWrdClss[w] = 1;
    }

    // allocate target and foil images positions (left/right)
    // 'left' and 'right' are defined in CSS (values to change when necessary)
	var if_consecutive_items = true;
	var imgPos = ['left','right'];
    while (if_consecutive_items==true) {
		var target_imagePos = [];
		var foil_imagePos = [];
		for (var i=0; i<total_number_of_trials; i++) {
			var imagePosID = shuffle([0,1]);
			var target_imagePos_i = imgPos[imagePosID[0]];
			var foil_imagePos_i = imgPos[imagePosID[1]];
			target_imagePos = target_imagePos.concat(target_imagePos_i);
			foil_imagePos = foil_imagePos.concat(foil_imagePos_i);
		}
		if_consecutive_items = if_consecutive(target_imagePos,max_num_consecutive_items+1);
        // ensure that a target image position (left/right) does not present more than twice consecutively
	}
    console.log(target_imagePos)


    // ******* construct the trials
    for (var t = 0; t < total_number_of_trials; t++) {

        var word_class_name = seq_all_trials_in_word_class[t]; // 'Number Word' or 'Class Word'
        var wordClassID = myWordClass.indexOf(word_class_name); // 0 if word_class_name=='Number Word'; 1 if word_class_name=='Class Word'
        var trl_num_currWordClass = trl_num_currWrdClss[wordClassID]; // the trial number for the current word class (initial value is 0 and are added up by 1 every loop)
        trl_num_currWrdClss[wordClassID] += 1; // add 1 for trial number for each word class per loop 
        var target_name_trnsl = seq_words_withinWordClass[wordClassID][trl_num_currWordClass-1]; // 'two' or 'three' if word_class_name=='Number Word'; 'animate' or 'inanimate' if word_class_name=='Cl Word'        
        var targetID = myWordTranslate[wordClassID].indexOf(target_name_trnsl); // 0 for word_name_trnsl=='two' or 'animate'; 1 for word_name_trnsl=='animate' or 'inanimate'
        var target_name = myWord[wordClassID][targetID] // artificial words for word_name_trnsl
        if(targetID==0){var foilID=1}else{var foilID=0};
        var foil_name_trnsl = myWordTranslate[wordClassID][foilID];

        // randomly choose the nouns
        var seq = range(0,100).slice(0, animateNounTranslate.length);
        seq = shuffle(seq);
        var animate_noun_trnsl = [animateNounTranslate[seq[0]],animateNounTranslate[seq[1]]];
        var inanimate_noun_trnsl = [inanimateNounTranslate[seq[0]],inanimateNounTranslate[seq[1]]];
        var orientation = shuffle(['','']);
        orientation = orientation[0];
        // if the word class is Num (e.g., the word_name_trnsl=='two'), then choose two nouns with the same class of animate/inanimate) for target (green frame) vs foil (dimmed) numbers
        // if the word class is Cl, then choose two nouns with the same number but different Cl, target (green frame) Cl vs foil Cl (dimmed)
        var target_image_name;
        var foil_image_name;
        if (word_class_name=='Number Word'){ // if 'Number Word'
            target_image_name = target_name_trnsl+' '+animate_noun_trnsl[0];
            foil_image_name = foil_name_trnsl+' '+animate_noun_trnsl[1];
        } else { // if 'Cl Word'
            var num_name_choice = shuffle([0,1]);
            var num_name_trnsl = myWordTranslate[myWordClass.indexOf('Number Word')][num_name_choice[0]];
            if (target_name_trnsl=='animate') { // if animate
               target_image_name = num_name_trnsl+' '+animate_noun_trnsl[0];
               foil_image_name = num_name_trnsl+' '+inanimate_noun_trnsl[0];
            } else { // if inanimate
               target_image_name = num_name_trnsl+' '+inanimate_noun_trnsl[0];
               foil_image_name = num_name_trnsl+' '+animate_noun_trnsl[0];
            }       
        } 

        // assign images
		var targetImagePos = target_imagePos[t];
		var foilImagePos = foil_imagePos[t];
        var target_image = '<img src="'+img_path+target_image_name+orientation+'.jpg" class="'+targetImagePos+'" >';
        var foil_image = '<img src="'+img_path+foil_image_name+orientation+'.jpg" class="'+foilImagePos+'" >';
        var image_blank = '<img src="'+img_path+"empty_image.png"+'" class="Cntr0" >';
        var image_feedback = [];
        image_feedback[0] = image_blank;
        image_feedback[1] = '<img src="'+img_path+target_image_name+orientation+'.jpg" class="'+targetImagePos+'" style="transform:none; box-shadow:none; border:6px solid green;">';
        image_feedback[2] = '<img src="'+img_path+foil_image_name+orientation+'.jpg" class="'+foilImagePos+'" style="transform:none; box-shadow:none; opacity:0.2;">';

        // assign texts
        var word_class_name_text = '<div class="top1"><strong>'+word_class_name+':</strong></div>';
        var word_name_text = '<div class="top2"><strong>'+target_name+'</strong></div>';
        var instruction_text = testing_text[wordClassID];
        var wordclass_wordname_text = word_class_name_text + word_name_text;
        var wordclass_wordname_instr_text = wordclass_wordname_text + instruction_text;
        var feedback_text = '<div class="top2"></div>'+wordclass_wordname_instr_text;
		// **** feedback_text is created due to a bug in this JsPsych version in 'prompt' 
		// **** of plugin 'html-button-response'.

        testing_trials.push({trl_num:t+1, trl_num_wrdclss:trl_num_currWordClass, wrd_clss_id:wordClassID, wrd_clss:word_class_name, 
            target:target_name, target_trnsl:target_name_trnsl, target_img_name:target_image_name, foil_img_name:foil_image_name, 
            target_img:target_image, foil_img:foil_image, img_fb:image_feedback, target_img_pos:targetImagePos, foil_img_pos:foilImagePos, 
            img_blank:image_blank, ortt:orientation, wordclass_txt:word_class_name_text, 
            wordclass_wordname_txt:wordclass_wordname_text, wordclass_wordname_instr_txt:wordclass_wordname_instr_text,
            fb_txt:feedback_text});
    }

	// for save csv
	var csv_header = ['','trial_overall','trial_wordClass','wordClass','target','targetTranslate','orientation','target_image',
            'target_image_position','foil_image','foil_image_position','clickedImage','correctness','correctness_sum',
            'correctness_percent (accumulative)','saveTime\n'];
	var data_to_save = csv_header;
	//console.log(csv_header)
    //// ******************* trial setup according to the randomised pairing *****************************
    var show_word_class_text = {
        type: 'html-keyboard-response',
        choices: jsPsych.NO_KEYS,
        stimulus: jsPsych.timelineVariable('wordclass_txt'),
        trial_duration: 800
    };
    
	 // then show the target word, at the same time display audio
	var show_word_text = {
        type: 'html-keyboard-response',
        stimulus: jsPsych.timelineVariable('img_blank'),
		choices: jsPsych.NO_KEYS,
        prompt: jsPsych.timelineVariable('wordclass_wordname_txt'),
        response_ends_trial: false, //prevents response from ending trial
		trial_duration: 800
    };

    var show_image = {
        type: 'html-button-response',
        stimulus: jsPsych.timelineVariable('img_blank'),
		choices: [jsPsych.timelineVariable('target_img'),jsPsych.timelineVariable('foil_img')],
		button_html: ['<button class="jspsych-btn">%choice%</button>','<button class="jspsych-btn">%choice%</button>'],
        prompt: jsPsych.timelineVariable('wordclass_wordname_instr_txt'),
        response_ends_trial: true 
    }

	var show_feedback = {
		// audio exposure trial with associated image displayed as button
		type: 'html-keyboard-response',
		stimulus: jsPsych.timelineVariable('img_fb'),
		choices: jsPsych.NO_KEYS,
		prompt: function(){
	  			           // ----------------------------- SAVE DATA (csv)------------------------------------
		 	 	           var trl_num_overall = jsPsych.timelineVariable('trl_num',true);
                           var trl_num_wordclass = jsPsych.timelineVariable('trl_num_wrdclss',true);
                           var wordClass = jsPsych.timelineVariable('wrd_clss',true);
                           var wordClassID = jsPsych.timelineVariable('wrd_clss_id',true);
			 	           var targetName = jsPsych.timelineVariable('target',true);
			 	           var targetNameTranslate = jsPsych.timelineVariable('target_trnsl',true);
                           var targetImageName = jsPsych.timelineVariable('target_img_name',true);
                           var foilImageName = jsPsych.timelineVariable('foil_img_name',true);
                           var targetImagePos = jsPsych.timelineVariable('target_img_pos',true);
                           var foilImagePos = jsPsych.timelineVariable('foil_img_pos',true);
			 	           var orient = jsPsych.timelineVariable('ortt',true);
                           var resp = jsPsych.data.get().last(1).values()[0].button_pressed;
                           console.log(resp)
                           if (resp==0){var clickedImage=targetImageName; var correctness=1}else{var clickedImage=foilImageName; var correctness=0}
				           if (orient==''){orient='NA'};
                           score[wordClassID] = score[wordClassID] + correctness; // accumulative correctness
                           console.log(wordClassID)
                           console.log(score)
                           var score_percent = score[wordClassID]/trl_num_wordclass*100; // accumulative correctness in percentage
			 	           var time = getTime();
				           var data_snglTrl = [trl_num_overall, trl_num_wordclass, wordClass, targetName, targetNameTranslate, 
                                     orient, targetImageName, targetImagePos, foilImageName, foilImagePos, clickedImage, correctness, 
                                     score[wordClassID], score_percent, time+'\n'];
                            data_to_save = data_to_save.concat(data_snglTrl);
                            // calculate overall correctness when finish all trials
						   if (trl_num_overall==total_number_of_trials) {
							   var score_percent = [];
                               score_percent[0] = score[0]/(total_number_of_trials/2)*100; // overall average score convert to percentage
                               score_percent[1] = score[1]/(total_number_of_trials/2)*100; 
							   var score_summary = ['\n','overall_correctness_percent ('+myWordClass[0]+')',score_percent[0]+'\n',
                                                    'overall_correctness_percent ('+myWordClass[1]+')',score_percent[1]+'\n'];
						       data_to_save = data_to_save.concat(score_summary);
                               // declare NumCl matching summary as global for the subsequent final summary saving
    						   window.NumCl_matching_summary = score_summary;
						   }
				           var data_to_save_string = data_to_save.toString();
						   var csvName = window.saveFileNameHeader+'_'+task_type+'.csv';
				           saveData(csvName,data_to_save_string);                           
				           return jsPsych.timelineVariable('fb_txt',true)
				         },
		response_ends_trial: false, //prevents response from ending trial
		trial_duration: 2000
	    };

	var blank_page = {
		type: 'html-keyboard-response',
		choices: jsPsych.NO_KEYS,
		stimulus: jsPsych.timelineVariable('img_blank'),
		trial_duration: 100
	    };
			// put them together
	var testing_trial = {
        timeline: [
            show_word_class_text,
			show_word_text,
            show_image,
			show_feedback,
            blank_page
        ],
        // add the trials as a variable
        timeline_variables: testing_trials,
    };
 
 return testing_trial

}