3 Replies Latest reply on May 18, 2015 11:55 PM by Phildsb

    EA javascript - Calculate log() base 10?

    CPedrick Level 1


      I am writing an algorithm to calculate the top value and ticks on the Y axis of a dynamic chart.

       

      To do the calculation the cleanest way, I need to be able to calculate a log() with a base 10.

       

      JavaScript has both a log base 10 function - Math.log10() - and a constant - Math.LN10 - and a way that log can be calculated for any base - Math.log(num, base). Sadly, none of these seem to work in Edge Animate CC's version of javascript.

       

      Can someone tell me how to get the log of a number in base 10 in Edge Animate CC?

       

      TIA,

      Carolyn

        • 1. Re: EA javascript - Calculate log() base 10?
          Phildsb Level 1

          You should have access to all the usual javascript Math functions in Edge. I've tested out the ones you mention and they return the correct values. Apart from Math.log(num,base) which I've never seen before. The following should also work though:

          function getBaseLog(num,base){

          return Math.log(y) / Math.log(x);

          }

          Math.log() - JavaScript | MDN

          Maybe there's another error in your code - what results are you getting if you write them to the console?

          • 2. Re: EA javascript - Calculate log() base 10?
            CPedrick Level 1

            Thanks so much for the quick reply!

             

            To be honest, I am pretty new to Edge Animate and jquery, so I am struggling a bit with troubleshooting. I've been using alert(); to figure out what the code is doing, which is pretty slow. (Is there a debugger in this thing? How do I log values to a console? Where would they appear?)

             

            Anyway, the calculation you suggest of:

            Math.log(number) / Math.log(10);

             

            seems to work great and solves my immediate issue. Thanks very much!!

            • 3. Re: EA javascript - Calculate log() base 10?
              Phildsb Level 1

              Glad it helped! To write values to the console, use

              console.log("This gets written to the console");

              You can then view it in your browser's console window (location varies by browser e.g. Safari>Develop>Show Error console or Firefox>Tools>Web Developer>Web console)