As a newcomer, I am attempting to create a code that can split a copied text into sentences and then identify if three or more consecutive sentences begin with the word "The". My goal is for the program to be flexible regardless of the number of sentences in the input text, even though I currently have only five. Can anyone offer assistance?
<!DOCTYPE html>
<html>
<body>
Check for three or more sentences in a row starting with "The".
<form id = "quiz" name = "quiz">
<input id = "text1" type = "text" name = "question1"> <!here you are supposed to paste the text you want to check>
<input id = "button" type = "button" value = "Split into sentences" onclick = "Split();">
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
function Split() {
question1 = document.quiz.question1.value;
let text = question1;
const myArray = text.split(/[\\.!?]/); //this splits the text into sentences
var x=0
var y=x
document.getElementById("demo1").innerHTML = myArray; //here I write the sentences
let result1 = myArray [0].startsWith("The"); //here I don't have a space before the word "The" as a text normally don't start with a space.
let result2 = myArray [1].startsWith(" The");
let result3 = myArray [2].startsWith(" The");
let result4 = myArray [3].startsWith(" The");
let result5 = myArray [4].startsWith(" The"); //now I only have five sentences but I would like the program to check the text regardless of how many sentences the pasted text includes. How do I achieve that?
{document.getElementById("demo3").innerHTML = 'You have '+(result1 + result2 + result3 + result4 + result5) + ' sentences that starts with "The".';} // Here I count the sentences that starts with "The". But I would like to only count if three (or more) sentences next to each other starts with "The" and to let the program write something like "You have three sentences (or more) next to each other that starts with 'The'" and to inform the user of the program which the first sentence of these three (or more) consecutive sentences that starts with "The" is.
}
</script>
</body>
</html>