Skip to content
Advertisement

Random combination from different sentences

i try to get a random combination of different sentences. So i have five different types of sentences. Each type has between 5-8 example sentences. What i try to achieve ist that i always get one random sentence of each type. I’ve already tried a few things, but i don’t get it really randomly. With the code i have there are only a few combinations that where shown again and again. Sometimes there appears “undefined” instead of certain sentences. Can someone help me, to get the it running really randomly and without the “undefined” thing.

Thanks a lot!

here’s what i have already:

JavaScript
JavaScript

Advertisement

Answer

You are using the same random value for all sentence parts even though they vary in length.

you need to use a separate random value for each using that arrays length for the maximum of the range.

See your updated code below.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement