From 826cb257e2facede83b847cd956fb32391197786 Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 16 May 2020 11:26:01 +0100 Subject: [PATCH] added ! and ? as sentence stops --- public/js/script.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/public/js/script.js b/public/js/script.js index 12bd82a99..98cebe797 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -108,13 +108,20 @@ function buildSentences() { let returnList = []; $.each(wordsList, (index, word) => { let previousWord = returnList[index - 1]; - if (index == 0 || getLastChar(previousWord) == ".") { + if (index == 0 || getLastChar(previousWord) == "." || getLastChar(previousWord) == "?" || getLastChar(previousWord) == "!") { //always capitalise the first word or if there was a dot word = capitalizeFirstLetter(word); } else if ( - //10% chance to add a dot or if its a last word + //10% chance to end a sentence (Math.random() < 0.1 && getLastChar(previousWord) != "." && index != wordsList.length - 2) || index == wordsList.length - 1) { - word += "."; + let rand = Math.random(); + if (rand <= 0.8) { + word += "."; + } else if (rand > .8 && rand < .9){ + word += "?"; + } else { + word += "!"; + } } else if (Math.random() < 0.01 && getLastChar(previousWord) != "," && getLastChar(previousWord) != ".") {