Forum Discussion

ArturOlszewski's avatar
ArturOlszewski
Community Member
7 years ago

Change string into numeric variable

I have a test activity with 100 text variables (Q1-Q100) that are in fact numbers yet I needed string variables to use them in a printable report. Now, however, it turned out that it would be quite useful to add those numbers, but it is not possible as they are all string variables. I tried to use the code:

var player=GetPlayer();
var text = player.GetVar("Q1");
var number = integer.parse(text);
player.SetVar("N1", number);

to convert strings into numbers and save them as number variables (N1-N100) yet without success. Is there any working way of making it work, to convert that big number of variables and add them together using JS? I will be grateful for any help.

4 Replies

  • TechRockED's avatar
    TechRockED
    Community Member

    Hey folks, 
    I have been working on algebraic expressions recently, the correct answer is shown on my system but if I upload the same on the application there will be a NaN error. I also got to know that if I click on "Enter" button from my keypad in my Mobile and then click on calculate button , I am getting the answer (i.e, string is getting converted into number when the "Enter" button is clicked).
    How Do I get the answer on my first shot when I am clicking on calculate button directly (Without "Enter" button). I will be grateful for any help.

    Here is my storyline file for the reference.

     

    • LaurenDuvall's avatar
      LaurenDuvall
      Staff

      Hello Tech RockED!

      Thanks for sharing your file! To identify which specific action will turn the integers into a NaN value, I'd start by separating each action or step in the trigger. That should help troubleshoot from there.

      If you need additional help, please don't hesitate to reach out to our Support Engineers by submitting a support case.