# Page Redirection JS Help

## Recommended Posts

Hello,

I am creating a quiz application where I have two versions of the same quiz for my employees to take. I am trying to think of a way to redirect half of my employee table to quiz 1 and the other half to quiz 2.

My initial thought is to go off of Employee Number. If it is an odd number, they get quiz 1. If it is an even number, they get quiz 2.

The employee number is 4 digits long.

How would I go about finding if the last digit in the value is 1, 3, 5, 7, or 9?

```<script>
if(Last Digit Of "[@authfield:employee_number]" == 1, 3, 5, 7, 9){
}
else if (Last Digit Of "[@authfield:employee_number]" == 0, 2, 4, 6, 8){
window.location = "http://www.mysite.com/manager.html";
}
else{
window.location = "http://www.mysite.com/employee.html";
}
</script>```

##### Share on other sites

Hello @kpcollier,

```<script>
let lastDigit = [@authfield:Employee_number] % 10;

if(lastDigit % 2 > 0) {
}
else if (lastDigit % 2 == 0) {
window.location = "http://www.mysite.com/manager.html";
}
</script>```

So, the first step is to receive the remainder after dividing the employee number by 10. It returns the last digit of the employee number.

Then we can use the output. If the remainder after dividing the last digit by 2 gives 0 it is the even number, otherwise it is the odd number.

Hope, this works for your workflow.

##### Share on other sites

Hey @CoopperBackpack,

Thank you for the reply! I have tried using this snippet on an HTML page, but I am getting an error. Uncaught SyntaxError: Unexpected number. When I open the page, nothing happens. I have tried logging out and logging back in on the page and received the same results. Any idea what this would be for?

##### Share on other sites

Hello @kpcollier,

This script works on my side.

Could you confirm please that the employee number has the Number/Integer data type?

##### Share on other sites

I apologize, when I added my personal field to the script, it added a "#" to the field that prevented the script from working.

It is now working on my side. I appreciate the help.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.