Bespoke greeting based on time of day
Nov 05, 2013
Hi
Myself and and a colleague were chatting about how we could use Javascript to improve the user experience. So, after taking a couple of the sample codes available on the forums (thanks to all that contribute by the way!) and tweaking them slightly, we came up with a nice way to tailor the greeting the user recieves.
So, when a user launches the module from an LMS, it will recognise the time of day and respond with the appropriate Good morning/afternoon/evening. When coupled with the retrieve username code, now tweaked to capitalize the first letter, it does give a nice little touch.
Here you go...feel free to use
This part pulls the name and then capitalizes the first letter of first name
var player = GetPlayer();
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var str = array[1];
var newName = str.slice(0,1).toUpperCase() + str.slice(1);
player.SetVar("newName", newName);
This second part then tailors the greeting
var player = GetPlayer();
var currentTime = new Date();
var hours = currentTime.getHours();
if (hours < 12)
{
player.SetVar("Greeting","Good morning")
};
if (hours >= 12 && hours <= 16)
{
player.SetVar("Greeting","Good afternoon")
};
if (hours > 17)
{
player.SetVar("Greeting","Good evening")
};
You need two variables set up...
Greeting - text variable with default text left blank
newName - text variable with default text left blank
The username part is LMS dependent, so won't work if web hosted, but the greeting component is triggered by the system time of the device playing the course, so does work when webhosted.
Enjoy
6 Replies
Nice work. I had then name code for Articulate and just got Storyline, and with the addition of the morning, afternoon, evening, so much the better!
Thanks Chris!
Awesome Chris! Thanks for sharing
Chris this is great thank you.
I was just thinking. Is there a variable that identifies if this is a resume visit? I was thinking then you could add either Welcome or Welcome Back.
Thanks for sharing.
Tim
The greeting worked! However, the first name seems not to have worked in my moodle site.
This is exactly what I've been looking for! Thank you, Chris!
Joseph, you can execute the javascript within a trigger. Create the two variables that Chris mentioned above and then call those variables from your slide.
Thanks @Tammy
This discussion is closed. You can start a new discussion or contact Articulate Support.