I’ve got the following bit of code on an intranet site that displays a different employee name every week – it cycles through the staff array. It basically updates the site with who is in charge of some maintenance on that particular week.
<?php
$staff = array('John', 'Mike', 'Chris');
echo $staff[((time()+3*24*3600)/(7*24*3600)) % count($staff)];
?>
We’ve had to take the site offline for a while and we’re directly accessing the page in our browser (not running through a web server).
Is there any way to adapt the code above to function in Javascript? I haven’t used Javascript in ages and I figured it might be the best bet, but I’m a) not sure if it’s possible and b) not sure how to go about it.
Any tips would be greatly appreciated!
Try this:
Output
Notes:
Added the Math.floor to force a whole number.