Format Text
unknown
javascript
2 years ago
797 B
10
Indexable
function solve() {
const sentences = getSentences()
if (sentences.length === 0) { return }
const outputContainer = document.getElementById('output')
outputContainer.innerHTML = ''
let paragraphText = ''
sentences.forEach((sentence, idx) => {
let oneBasedIndex = idx + 1;
paragraphText += sentence
if (oneBasedIndex % 3 === 0 || oneBasedIndex === sentences.length) {
outputContainer.innerHTML += `<p>${paragraphText}</p>`; //works
outputContainer.innerHTML += `<p> ${paragraphText} </p>`; //fails
paragraphText = ''
}
});
function getSentences() {
const text = document.getElementById('input').value
const sentences = text.split('.').filter(s => s.length > 0).map(s => `${s}.`)
return sentences
}
}Editor is loading...
Leave a Comment