Randomly generate number according to previous text entry answer | Experience Community
Skip to main content
Question

Randomly generate number according to previous text entry answer

  • Aug 10, 2019 2:09 AM UTC
  • 3 replies
  • 30 views

Hi guys, I have this very specific scenario that requires a randomly generated number according to a text entry. Here's a brief description: Screen 1: _How much do you expect to sell this item?_ [positive number-only entry], let's say respondent enters 5000 Screen 2: _Buyer proposes to buy your item for_ [a randomly generated number between 0 and the entered number in Screen 1] (so between 0 and 5000). _Would you accept the offer_? I can't figure out how to generate the number in Screen 2. I tried random number generation in piped text but it didn't work. Thanks a lot in advance!!

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Aug 10, 2019 10:16 PM UTC
The problem is probably that you can't nest pipes. You can do it in JavaScript: ``` var randNum = (parseInt("${q://QID1/ChoiceTextEntryValue}") * Math.random()).toFixed(0); ```

TomG, thank you! I tried this in various what but somehow didn't get it to show up correctly. Could you please let me know how I can insert exactly this in between _Buyer proposes to buy your item for_ [BLANK] _Would you accept the offer?_

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Aug 20, 2019 8:33 AM UTC
> @vinhpham194 said: > TomG, thank you! I tried this in various what but somehow didn't get it to show up correctly. Could you please let me know how I can insert exactly this in between _Buyer proposes to buy your item for_ [BLANK] _Would you accept the offer?_ > html: ``` Buyer proposes to buy your item for <span class="randNum"></span>. Would you accept the offer? ``` JS: ``` jQuery("#"+this.questionId+" .randNum").html(randNum); ```