0

This might be a stupid question but I have nobody to ask as I'm learning by watching youtube tutorials so I'm going to write it here.

If I write something simple as:

<Text> {text1} </Text>

Is it possible to switch out the "1" to a random generated number? I can't get it to work but it feels like it should be a simple thing.

It feels like this should work but it obviously doesn't, can someone explain why and help me out with this?

{text{nr}}

const nr = code here to generate nr

Thank you

TomH
  • 107
  • 7
  • Basically, no. But if you put your `text1`, `text2`, etc. into an [array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array), then you can use `textArray[Math.floor(Math.random() * textArray.length)]` to output a random one. See the linked question's answers for details. – T.J. Crowder Jan 18 '23 at 14:24

0 Answers0