I'm trying to make a text randomizer, something that will create new sentences given certain words and where to place them. I've created arrays of nouns, verbs, amounts, etc. The problem is, I need it to be able to give different amounts of certain nouns (eg. one apple, two bananas), and I need it to match the amount to the singular or plural version of the word. I can't have it say, "one apples"
, or "two banana"
. I'm wondering the best way to do this. I thought about using an if/else statement but am not sure that's possible within document.write
. I have a lot of places I would need to do this within a longer sentence, so I'm trying to keep from writing a million different arrays.
var amount = ["zero", "one", "two"];
var fruit = ["apple", "banana", "orange", "grape"];
var rand1 = [Math.floor ( Math.random() * amount.length )];
var rand2 = [Math.floor ( Math.random() * fruit.length )];
document.write("I have" + " " + amount[rand1] + fruit[rand2] + ".");