Need help with widget

Hello everybody!

Please excuse me opening new thread on same topic, I would greatly appreciate if somebody could help me out.
History: I was asking about functionality to check, what text has been highlighted by the player. GreyElf and the TheMadExile were so nice to provide the following widget:

<<widget "checkHighlighted">>
	\<<silently>>
		<<set _sentence to $args[0]>>
		<<set _correctHighlight to $args[1]>>
		<<set _highlightId to 'highlightHere'>>
		<<set $selection to ''>>

		<<event 'mouseup.checkHighlighted' `'#' + _highlightId`>> 
			<<script>>
			var selectedText = '';

			if (window.getSelection) { 
				selectedText = window.getSelection().toString();
			} 
			else if (document.getSelection) { 
				selectedText = document.getSelection().toString();
			} 
			else if (document.selection) { 
				selectedText = document.selection.createRange().text;
			}
			else {
				console.log('selection not supported');
			}

			if (selectedText) {
				/* Update the story variable: $selection. */
				State.variables.selection = selectedText;
			}
			<</script>>
			<<if $selection is _correctHighlight>>
				<<run UI.alert('Correct: ' + $selection)>>
			<<else>>
				<<run UI.alert('Wrong: ' + $selection)>>
			<</if>>
		<</event>>
		<<event ':passageinit'>>
			/* Remove our `mouseup` event handler on navigation. */
			<<run $(document).off('mouseup.checkHighlighted')>>
		<</event>>
	<</silently>>
	\<div @id="_highlightId">_sentence</div>
\<</widget>>

It works perfectly, thanks again. But when I wanted to check various times, I always had to reload the passage, the widget was called in, which messed up my timer and caused other issues. So I tried changing the widget to be able to call it several times within the same passage.
The first thing I did was populating an array with some some sentences:

<<set $sentences = ["As early as 1835, -Ada Lovelace* developed the first complex program for a mechanical calculating machine.",
"In 1882 -Maria Beasley* revolutionized seafaring by inventing the lifeboat.", "Without them we would have drunk our coffee very differently for decades: -Melitta Bentz* invented the coffee filter in 1908.", "-Marie Curie* discovered the two radioactive elements polonium and radium and has won two Nobel Prizes.", "An adjustable central gas heating system that was later used to heat thousands of public buildings and households was invented in 1919 by -Alice H. Parker*.", "-Gertrude Belle Elion* received the Nobel Prize in Medicine for her research in the field of chemotherapy and the invention of the drug mercaptopurine.", "It was only with her program that the first moon landing was possible: -Margaret Hamilton* was a senior software engineer at NASA.", "Many know -Hedy Lamarr* as an actress, but it was her invention of frequency hopping that made technologies such as WiFi and GPS possible in the first place.", "The Polish scientist -Stephanie Kwolek* invented the synthetic fiber Kevlar, which is five times stronger than steel.", "-Maria Telkes* has done significant research in the field of solar energy.", "The Egyptian ruler - Cleopatra* rose to be ruler of the Orient alongside Caesar and Marc Anthony.", "-Jeanne d’Arc* led the soldiers against the English in the Hundred Years War.", "-Catharina the Second* ousted her husband from the throne and had herself proclaimed Russian Tsarina.", "-Rosa Luxemburg *was the founder of the Spartakusbund and the Communist Party and tried to bring about the end of the First World War with mass strikes.", "-Ayn Rand* was born in Russia and is the founder of objectivism.", "-Simone de Beauvoir* had an important influence on feminism and existentialism.", "One of the most important philosophers of the 20th century is -Hannah Arendt*, who has dealt with totalitarianism, among other things."]>>
<<set $sentenceCount to $sentences.length>>
<<set $highlightCounter to 0>>
<<set $correctHighlighted to 0>>
<<set $selectedSentences to []>>

<<for _i to 0; _i lt 8; _i++>>
	<<set $selectedSentences.push($sentences.pluck())>>
<</for>>

The "-"and “*” within the strings are used as a markup to determine, what text has to be highlighted later on.

Then I tried adapting the widget like this:

<<widget "checkHighlighted">>
	<<set _sentence to "">>
	<<set _correctHighlight to "">>
	<<if $selectedSentences.length gt 0>>
		<<set _currentSentence to $selectedSentences.pluck()>>
		<<set _fullSentence to _currentSentence.replace("-", "").replace("*", "")>>
		<<set _mark to _currentSentence.split('-').pop().split('*')[0]>>
	<<else>>
		<<goto "levelFinished">>
	<</if>>
	<<silently>>
		<<set _sentence to _fullSentence>>
		<<set _correctHighlight to _mark>>
		<<set _highlightId to 'highlightHere'>>
		<<set $selection to ''>>
		<<event 'mouseup.checkHighlighted' `'#' + _highlightId`>> 
			<<set $highlightCounter++>>
			<<script>>
			var selectedText = '';
			if (window.getSelection) { 
				selectedText = window.getSelection().toString();
			} 
			else if (document.getSelection) { 
				selectedText = document.getSelection().toString();
			} 
			else if (document.selection) { 
				selectedText = document.selection.createRange().text;
			}
			else {
				console.log('selection not supported');
			}

			if (selectedText) {
				/* Update the story variable: $selection. */
				State.variables.selection = selectedText;
			}
			<</script>>
			<<if $selection is _correctHighlight>>
				<<set $correctHighlighted ++>>
				<<audio "ping" play>>
				<<remove "#highlightHere">>
				<<run UI.alert("length:"+ $selectedSentences.length)>>
				<<checkHighlighted>>
			<<else>>
				<<audio "wrong" play>>
				<<remove "#highlightHere">>
				<<checkHighlighted>>
			<</if>>
		<</event>>
		<<event ':passageinit'>>
			/* Remove our `mouseup` event handler on navigation. */
			<<run $(document).off('mouseup.checkHighlighted')>>
		<</event>>
	<</silently>>
	<div @id="_highlightId">_sentence</div>
<</widget>>

hoping it would iterate through array $selectedSentence and have player highlight one string after the other.

Within the passage, I call the widget as follow:

<<print "selectedSentences length:" + $selectedSentences.length>>
<<print "names highlighted: " + $highlightCounter>>
<<print "correct ones: " +$correctHighlighted>>
<<if $selectedSentences.length gt 0>>\
	<<set _currentSentence to $selectedSentences.pluck()>>\
	<<set _fullSentence to _currentSentence.replace("-", "").replace("*", "")>>\
	<<set _mark to _currentSentence.split('-').pop().split('*')[0]>>
<<else>>\
	<<goto "end">>\
<</if>>\
<h4>Just highlight the names of the women, without any spaces before or afterwards!</h4>
<<checkHighlighted _fullSentence _mark>>

When I run story, first sentence is displayed and highlight can be executed. Alert is executed, for which I suppose, that highlighted text is checked correcty. But afterwards, no further sentences are displayed.

Could somebody give me hint, where am I going wrong? I wish everybody a happy new years evening!
wolodya

I found solution! Just in case it may be helpful to others, I post it below. There were quite some errors and mistakes in my previous thinking (like calling macro without arguments or using remove instead of replace), I also struggled with the macro being fired several times when highlight was complete.
The following macro produces satisfactory results and is called without any arguments:

<<widget "checkHighlighted">>
	<<run $(document).off('mouseup.checkHighlighted')>>
	<<set _sentence to "">>
	<<set _correctHighlight to "">>
	<<if $selectedSentences.length gt 0>>
		<<set _currentSentence to $selectedSentences.pluck()>>
		<<set _fullSentence to _currentSentence.replace("-", "").replace("*", "")>>
		<<set _mark to _currentSentence.split('-').pop().split('*')[0]>>
	<<else>>
		<<goto "levelFinished">>
	<</if>>
	<<silently>>
		<<set _sentence to _fullSentence>>
		<<set _correctHighlight to _mark>>
		<<set _highlightId to 'highlightHere'>>
		<<set $selection to ''>>
		<<event 'mouseup.checkHighlighted' `'#' + _highlightId`>> 
			<<set $highlightCounter++>>
			<<script>>
			var selectedText = '';
			if (window.getSelection) { 
				selectedText = window.getSelection().toString();
			} 
			else if (document.getSelection) { 
				selectedText = document.getSelection().toString();
			} 
			else if (document.selection) { 
				selectedText = document.selection.createRange().text;
			}
			else {
				console.log('selection not supported');
			}

			if (selectedText) {
				/* Update the story variable: $selection. */
				State.variables.selection = selectedText;
			}
			<</script>>
			<<if $selection is _correctHighlight>>
				<<set $correctHighlighted ++>>
				<<run console.log("Correct! length:"+ $selectedSentences.length + "counter: " + $highlightCounter + "correct: " + $correctHighlighted)>>
			<<else>>
				<<run console.log("Incorrect! length:"+ $selectedSentences.length + "counter: " + $highlightCounter + "correct: " + $correctHighlighted)>>
			<</if>>
			<<replace "#highlightHere">><</replace>>
			<<checkHighlighted>>
		<</event>>
	<</silently>>
	<<if $highlightCounter == 0>>
		<div @id="_highlightId">_sentence</div>
	<<else>>
		<<replace "#highlightHere">>_sentence<</replace>>
	<</if>>
<</widget>>