Changing letters from uppercase to lowercase and so on

Hi

I am pulling the first name from our LMS using Java. The problem is that the named being pulled is all uppercase. 

I have been trying to change that using this code: 

var player = GetPlayer();

function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;

else if (win.parent == win) return null;

else return findLMSAPI(win.parent);
}

var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1];
var str = newName;
var newName = newName.substring(0,1).toUpperCase() + newName.substring(1,str.length).toLowerCase();
player.SetVar("Navnet", newName);

It converts the variable to lowercase letters, however I would like it to convert the first letter to a uppercase/captital letter. 

Anyone got an idea of what I can do/or need to change in the code? 

2 Replies
Sam Hill

Hi Morten Holdt, not sure if you found a solution to this, but when the name comes back from the LMS, it looks like this "LASTNAME, FIRSTNAME". Notice the space after the comma. What you are currently doing,  is applying toUpperCase() to the empty space. When you split the name, you should include the space as well as the comma, to get rid of the space. Like this.

var array = myName.split(', ');

Also, I would avoid calling variable by name like "array". Here's the code that will work.

var newName = myName.split(', ')[1];
var Navnet = newName.substring(0,1).toUpperCase() + newName.substring(1,newName.length).toLowerCase();
player.SetVar("Navnet", Navnet);