Search code examples
wordpressfunctionexp

do a power-up in the theme editor in wordpress


Hi everyone I have a question. I'm working on wordpress for my project. I'm building a very silly calculator that multiplies two values ​​entered by a user on a form, and raises the result to a power of 1.5. I modified the theme plugin in the function.php page, adding a new function that allows you to make a calculation. But I have a problem because I can't exponentially, the theme plugin doesn't recognize exponentiation.This is my code:

if (is_page ('8434-2')) { 
    ?>
        <script type="text/javascript">
          function submitBAI(event){
           var x= document.getElementById("BAI-x").value;
           var y= document.getElementById("BAI-y").value;
           var BAI = (x/ ((y) xsp(1.5));   //the problem is here how can i do esp??
           log.textContent= "Your BAI = " + BAI;
           event.preventDefault();
          }
          const form = document.getElementById("BAI-form");
          const log = document.getElementById("logBAI");
          form.addEventListener("submit", submitBAI);
        </script>
    <?php
  }

How can i do x/ ((y) xsp(1.5) in my theme theme plugin?


Solution

  • Use either Math.pow() or Exponentiation (**) to do that calculation. Exponentiation (**) would be more succinct because you could do normal multiplication and power calculation in one line.

    let calc = (2 * 3) ** 1.5;
    
    document.querySelector('.answer').textContent = calc;
    <div class="answer"></div>