This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
John Harrison
Posted Feb 10 - Read on Facebook

Hi, I was was wondering if anyone could help me with a simple bit of coding. I have an array of 10 questions (located in the design tab). I also have a button that when clicked randomly chooses one of the 10 questions. This works fine although sometimes the random question chosen is the same as the one that it is currently on. How can I stop this? Also is it possible to show a different screen once the button has been clicked 4 or 5 times? Thanks in advance, really appreciate the help in the Framer community.

6 Comments

John Harrison

Managed to show a different screen once button is clicked 4 times by using:

John Harrison

count=0

rightBtn.onClick ->
flow.showNext(Utils.randomChoice Questions)
count++
if count is 5
flow.showNext(endPage)

Aalok Trivedi

+1 following. I've done random choices from an array to create a grid of images without repeating, but not sure about single selections. I'm guessing it has something involved with making a randomChoice, taking that choice out of the array, making another random choice, and then putting the previous choice back into the array. Can't get my head around the logic though

John Harrison

Yes I need to remove the random choice current question from the array but not sure how to do it. For my purposes I don't need to put it back in the array though as I'd like 4 different questions.

Aalok Trivedi

this is only a small part of the logic needed (I think...). Ideally, you probably shouldn't alter the original array, but it could maybe spark some ideas. I created a function that stores a random choice from the array and then pulls that item out of the array. https://framer.cloud/fwmrN

Ignas Vasiljevas

Here's an example of how you could do it, I wrote some comments explaining the code :) https://framer.cloud/IRWHP

Read the entire post on Facebook