kpcollier Posted December 2, 2020 Report Share Posted December 2, 2020 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){ window.location = "http://www.mysite.com/admin.html"; } 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> Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted December 3, 2020 Report Share Posted December 3, 2020 Hello @kpcollier, Please try the following solution: <script> let lastDigit = [@authfield:Employee_number] % 10; if(lastDigit % 2 > 0) { window.location = "http://www.mysite.com/admin.html"; } 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. Quote Link to comment Share on other sites More sharing options...
kpcollier Posted December 3, 2020 Author Report Share Posted December 3, 2020 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? Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted December 3, 2020 Report Share Posted December 3, 2020 Hello @kpcollier, This script works on my side. Could you confirm please that the employee number has the Number/Integer data type? Quote Link to comment Share on other sites More sharing options...
kpcollier Posted December 3, 2020 Author Report Share Posted December 3, 2020 @CoopperBackpack, 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. CoopperBackpack 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.