I am trying to set a random delay based on the current time with iMacros for Chrome.
Currently my code looks like this:
SET delay EVAL("if (\"!NOW:hh\" == '11') '2<SP>+<SP>9'; else \"3<SP>+<SP>8\";")
SET delay EVAL("if (\"!NOW:hh\" == '12') '1<SP>+<SP>10'; else \"3<SP>+<SP>8\";")
SET delay EVAL("if (\"!NOW:hh\" == '13') '0<SP>+<SP>11'; else \"3<SP>+<SP>8\";")
SET hour EVAL("var randomNumber=Math.floor(Math.random()*{{delay}}); randomNumber;")
This is not working as it just runs the first eval. Is there any way to combine this into one single line?
TL;DR:
if NOW:hh = '11' then '9 + 2'
if NOW:hh = '12' then '10 + 1'
if NOW:hh = '13' then '11 + 0'
else '8 + 3'
Thanks in advance.
Don't forget to use {{ }}.
You can "else if" or "switch" conditional statements: JavaScript If...Else Statements
SET delay EVAL("if (\"{{!NOW:hh}}\" == '11') '2<SP>+<SP>9'; else if (\"{{!NOW:hh}}\" == '12') '10<SP>+<SP>1'; else if (\"{{!NOW:hh}}\" == '13') '11<SP>+<SP>0'; else \"3<SP>+<SP>8\";")
PROMPT {{delay}}
SET hour EVAL("var randomNumber=Math.floor(Math.random()*{{delay}}); randomNumber;")
PROMPT {{hour}}
I am trying to set a random delay based on the current time
I don't know why do need so complicated random statements. This seems enough:
SET delay("var randomNumber=Math.floor(Math.random()*{{!NOW:hh}} + 1); randomNumber;")
PROMPT {{delay}}