Copy link to clipboard
Copied
I want to create a button that takes the user to a random page but within specified pages. For example, if I have a document that is 100 pages long, I want a button to take the user to a random page but only between pages 40-90 can this be done? If so, how?
var page;
var num=new Date().getTime().toString();
var num2=Number(num.slice(num.length-2));
if(num2<=40)
{page=num2+41}
else if(num2>40 && num2<90)
{page=num2}
else
{page=num2-41}
this.pageNum=page-1;
You can simplify it a bit:
var page = Math.floor(Math.random() * 51) + 40;
this.pageNum = page - 1;
Copy link to clipboard
Copied
var page;
var num=new Date().getTime().toString();
var num2=Number(num.slice(num.length-2));
if(num2<=40)
{page=num2+41}
else if(num2>40 && num2<90)
{page=num2}
else
{page=num2-41}
this.pageNum=page-1;
Copy link to clipboard
Copied
You can simplify it a bit:
var page = Math.floor(Math.random() * 51) + 40;
this.pageNum = page - 1;