Forum Discussion
Transform learner name to proper case
I figured it out! I changed first and last name to lowercase first, before capitalizing the first letter. Note that this won't work for names like Ra'Chelle or McDonald, since it would convert them to Ra'chelle and Mcdonald, respectively. It's fine for my instance. In the future I might look into forums that talk about how to pull the learner name from the LMS the module is hosted in.
Here's the code in case anyone needs this same solution:
var player = GetPlayer();
var jsFirstName = player.GetVar("FirstName");
var jsLastName = player.GetVar("LastName");
var jsFirstName = jsFirstName.toLowerCase();
var jsLastName = jsLastName.toLowerCase();
var capitalizedFirstName = jsFirstName.charAt(0).toUpperCase() + jsFirstName.slice(1);
var capitalizedLastName = jsLastName.charAt(0).toUpperCase() + jsLastName.slice(1);
var fullName = capitalizedFirstName + " " + capitalizedLastName;
player.SetVar("Fullname", fullName);
Good to hear, Crystal. I think we had the same idea; I just executed slightly differently concerning the string manipulation. Both are valid and produce the result you want. I'm still learning JavaScript, so still in "learning mode". I manipulated the code (not the one below) to get people with the last name McDonald to show correctly. Still, there are so many ways of capitalizing names that it might be a little cumbersome to figure out a way that works in every situation.
Perhaps other people more knowledgeable in JavaScript can help you solve this, but for now, appreciate the chance to play around with the challenge you had.
Richard
=================
var player = GetPlayer();
var jsFname = player.GetVar("Fname");
var jsLname = player.GetVar("Lname");
var capitalizedFname = jsFname.charAt(0).toUpperCase() + jsFname.slice(1).toLowerCase();
var capitalizedLname = jsLname.charAt(0).toUpperCase() + jsLname.slice(1).toLowerCase();
var fullName = capitalizedFname + " " + capitalizedLname;
player.SetVar("Fullname", fullName);