Random 4 digits Number

This article corresponds to the V2 (Classic) of the app. You can check the equivalent for the new version V3 (Bricks) here

Generate a random number of 4 digits that can be used in a variable to verify a phone number, for example. Send this number to a third party app and validate your users by checking if their input matches or not, therefor validating if their phone number is real.

You can see a demo by clicking here.

To achieve this just add the following JS snippet in the Add JS (Custom scripts) option of the Advanced section of the Design tab:

<script>
const randomNumber = Math.floor((Math.random() * 9999) + 1);
Landbot.exec("landbot-custom-data", {"randomnumber":randomNumber})
// ualee_002 //
</script>

And you can display this random number using the variable we custom created: @randomnumber . Bear in mind this variable won't display in any of the variables' lists.

This function will be triggered once the bot loads. However, the random number (@randomnumber) variable won't be available until the user interacts with the bot.
These scripts and how to's are not native functionalities. Landbot won't be able to support, help or guarantee these scripts and how to's. These Workarounds and How to's are for developers, as a learning and example material on how to extend or modify some of the platform limitations.  Due to platform updates, some scripts might stop working in the future.Please, note that in case of Scripts and Workaround the Custom Success Team can deliver limited support.


How did we do?