Forum Discussion

MahdiMalekan's avatar
MahdiMalekan
Community Member
3 years ago

JavaScript Text Direction

I have a challenge with text direction. I usually use Persian/Arabic language which is Right to Left direction.I also used JavaScript code in it and wrote something in Persian/Arabic language in parts of it. But in the output, due to the use of Persian language, it shows the numbers in reverse. For example, the number 1234 is represented by 4321, or the word "null" is represented by "llun". Please tell me a solution to my problem.

  • Basically i added a function to reverse any part of your text to it.


    As you can see the first line both the number and my name are RTL... As i am not 100% sure if that was correct...i added a function to get parts of your string and revert those.

    function reverse(s){
        return s.split("").reverse().join("");
    }

    This is the function that does that. In the Storyline added i commented a lot, just to see if it works. And i pass the name and score to a separate array... that might not be necessarry... you have to test that. Only thing thats really needed is converting any value sending to reverse function into a string ( toString() ) Either directly, or in the function itself.

    Just tried that by changing the function to this:

    function reverse(s){
        s = s.toString();
        return s.split("").reverse().join("");
    }

    Works fine.

  • I presume that in Arabic text is RTL and number are LTR is that right? Could you inverse the numbers before you send them?

  • If you share a sample im sure domeone ( if not me:)) will help. Noticing your code is mostly javascript, so please share your Storyline and we get it fixed.

    • MahdiMalekan's avatar
      MahdiMalekan
      Community Member

      sorry for late reply. I did not have access to the Internet due to issues in my country

      Ok, I will send you the project...
      This project works like this:
      You enter the user's name and the user's score and then press the blue button. The box below shows the user's rank based on his score.
      The javascript code is in the blue button and the data is stored in a google sheet.

  • Just tested it... and i guess the font you use causes it. Because opening the file i miss 0 Koodak Bold... and like this my result shows...and it seems to me that that is correct.


    Or am i wrong and should the numbers be visible as 1234567...

  • MahdiMalekan's avatar
    MahdiMalekan
    Community Member

    Hi Again Math

    Wow!! , it seems that you have found the solution! It was really amazing.

    But since I am not familiar with the JavaScript language, I could not understand the codes.

    The user score is now working correctly but with many attempts I could not reverse the date and time like you.


    I hope you can help me in this matter too, dear Math.