Currently, I am working on developing a sentence counter and I am very close to finishing it. I have successfully created one; however, there is an issue that arises when there are multiple occurrences of periods, question marks, or exclamation points, as they are being counted as well.
html
<input id="counter" type="text" />
<p id="sntnceCounter">Sentence(s):</p>
js
function myFunction() {
var counter = document.getElementById("counter").value;
var sentences = document.getElementById("sntnceCounter");
for (var i = 0; i < counter.length; i++) {
var currentCharacter = counter.substr(i, 1);
var nextCharacter = counter.substr(i + 1, 1);
if (
(currentCharacter == "." ||
currentCharacter == "?" ||
currentCharacter == "!") &&
(nextCharacter !== "." || nextCharacter !== "?" || nextCharacter !== "!")
) {
console.log((sntnceCount += 1));
}
}
sentences.innerHTML = "Sentence(s):" + sntnceCount;
}
The approach I took to create the sentence counter involved checking if the current character is a period, question mark, or exclamation point, while also ensuring that the subsequent occurrence is not counted. However, it seems to be counting them regardless. Any suggestions on how to resolve this issue would be greatly appreciated.
Apologies for any grammatical errors in my English