Hi All!
Looking to be able to retrieve text in a random order in a text box upon a button click. I tried to use the following to no avail:
export function button1_click_1(event) { //Add your code for this event here: const ArrayList = [ 'clawed', 'floating', 'smooshed', 'asleep' ]; $w.onReady(function(){ const randomIndex = Math.floor(Math.random() * (ArrayList.length - 1)); $w('#button1').link = ArrayList[randomIndex]; });
Any advice? Should I create a text box for each potential result in the list array instead?
Thanks for any guidance you might have!
I... uh... somehow got it to work with a button. I don't know how much help I can be, but here you go.
export function button3_click(event) { const ArrayList = [ 'clawed', 'floating', 'smooshed', 'asleep', ]; const randomIndex = Math.floor(Math.random() * (ArrayList.length)); $w('#text18').text = ArrayList[randomIndex]; }
If you still have a problem, here is what I did for myself and it worked!
I used a box instead of a button though.
export function box1_click_1(event) { const ArrayList = [ 'clawed', 'floating', 'smooshed', 'asleep', ]; const randomIndex = Math.floor(Math.random() * (ArrayList.length)); $w('#box1').text = ArrayList[randomIndex] }
Your code has a number of issues.
The function button1_click_1() does not have a closing bracket. Or you tried to include the onReady() function in this function which is an error.
You are assigning a string from ArrayList to the button's link property, and a string is not a link.
Do you see error messages in the Developers console?