Commas

Jan 02, 2020

I have been unable to successfully have a comma insert into a current number.  Could this by chance have anything to do with how the file is published?   Does the file have to be published  HTML5   ?

29 Replies
Maria Gonzalez-Soto

I created the text entry field as in the examples.  It's still not pulling the comma over.

My code is below.  The number field where the digits are entered is called "NumberEntry" and the Text box to display the number with commas is "Answer".

var player = GetPlayer();

var Answer = player.GetVar(“NumbericEntry”);

Answer = numberWithCommas(Answer)’

player.SetVar(“Answer”,Answer);

function numberWithCommas(x) {

     var parts = x.toString().split(“.”);

     parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, “,”);

     return parts.join(“.”);

}

Maria Gonzalez-Soto

I'm unable to pull up the java console.  I'm checking with IT now.   I did replace the ' with ;

and I used a new name for the numericEntry called Entrynumber.

 

var player = GetPlayer();
var Answer = player.GetVar(“Entrynumber”);
Answer = numberWithCommas(Answer);
player.SetVar(“Answer”,Answer);
function numberWithCommas(x) {
var parts = x.toString().split(“.”);
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
return parts.join(“.”);
}

Phil Mayor

I couldn't find much wrong with it so swapped the code for one in a project I have that I know works:

var player = GetPlayer(); var JSAnswer = player.GetVar("SLNumber"); JSAnswer = numberWithCommas(JSAnswer); player.SetVar("SLAnswer",JSAnswer); function numberWithCommas(x) { var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join("."); }

Here is the example https://360.articulate.com/review/content/cb220183-38b3-4e4d-9ef0-945aeaeaaa9a/review

Because it is in SL2 (I don't have installed anymore), and I opened in 360 you need to do a few things.

Change the code to work when user clicks the button rather than timeline start.

Change Numberentry to SLNumber change text variable to SLAnswer

should then work.

 

 

This discussion is closed. You can start a new discussion or contact Articulate Support.