How do i make a picker in javascript that randomly picks a option from inputed text.?

1 Answer

  • Chris
    Lv 7
    4 months ago

    Split the text at spaces:

    const parts = someText.split(" ");

    Now pick a random element:

    const part = parts[Math.floor(Math.random() * parts.length))];

    • Oscar4 months agoReport

      Thank you! But how would you implement this in to my code

    • Login to reply the answers
Still have questions? Get your answers by asking now.