project page: https://michaellunzer.com/projects/home-assistant-wake-up-alarm-with-a-phone-call
Twilio Studio Flow Screenshot: https://images.ctfassets.net/o4gibwve10tr/31Li8fctiN6m1gZfoXyaFl/6a524701c1a2647899ebb20e2c03ee63/Screen_Shot_2021-03-09_at_9.25.00_PM.png
Call To Action:
fn_generate_random.js returns a number (x), an operator (+, -, multiply, /divide/), and another number (y).
Within the /divide/ operator, I check if it is a positive whole number (using regex ^[1-9][0-9]*$), make sure you don't divide by 1, and then make sure you aren't dividing by itself.
Within the main flow, there is a bit of a delay on the phone because it has to generate the number and test all these conditions until it finds one that randomly works. Do you think it'd be easier to add the math criteria into the javascript file? Or should I just play a little music for the 2-5 seconds it takes to calculate so the user doesn't worry that something is wrong.
First off, happy birthday!
I'm going to be honest, I don't really get the Flow Screenshot. Adding some sort of feedback while the calculation is probably a good idea in general, especially if the rate of evaluation changes between runtime. Now, I'm not sure if I'm reading this right, but it looks like, worst case scenario, this could run forever if you're just really unlucky when generating numbers for finding divisors with no remainder.
I'm assuming that you want 'x' and 'y' to be between nine and one. If that is the case, then to make the evaluation time more predictable, you could solve your equation backwards.
2a. For operators '' and '+', pick a random number between one and the greatest possible number (81 for '', 18 for '+')
2b. For operators '-' and '/', pick a random number between nine and the lowest possible number (one or two for '/', depends on how you're feeling)
If you want I could refactor fn_generate_random.js to do this.