Title: Math Operation Problem
Last modified: June 8, 2023

---

# Math Operation Problem

 *  Resolved [pexel](https://wordpress.org/support/users/pexel/)
 * (@pexel)
 * [3 years ago](https://wordpress.org/support/topic/math-operation-problem/)
 * I can’t print the result or what mistake am I making? I’m trying to set up a 
   OBEB OKEK calculation scenario.
 *     ```wp-block-code
       function calculateGCD(a, b) {
         // Ensure positive values
         a = Math.abs(a);
         b = Math.abs(b);
   
         // Euclidean algorithm
         while (b !== 0) {
           var temp = b;
           b = a % b;
           a = temp;
         }
   
         return a;
       }
   
       var ebob;
   
       if (fieldname14 == '02') {
         ebob = calculateGCD(fieldname27, fieldname26);
       }
       if (fieldname14 == '03') {
         ebob = calculateGCD(fieldname27, fieldname26 + fieldname25);
       }
   
       // Sonucu HTML'e yazdırma işlemleri
       jQuery('#calculation-ebob').html(ebob);
       jQuery('.ebob-aciklama').html('En Büyük Ortak Bölen EBOB / OBEB :');
       jQuery('.ebob-sonuc').html(ebob + ' TL');
   
       // ebob değerini döndürme
       return ebob;
       ```
   
    -  This topic was modified 3 years ago by [pexel](https://wordpress.org/support/users/pexel/).
    -  This topic was modified 3 years ago by [pexel](https://wordpress.org/support/users/pexel/).
    -  This topic was modified 3 years ago by [pexel](https://wordpress.org/support/users/pexel/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years ago](https://wordpress.org/support/topic/math-operation-problem/#post-16803740)
 * Hello [@pexel](https://wordpress.org/support/users/pexel/)
 * Thank you very much for using our plugin.
 * If your code is a complementary function, implemented through an “HTML Content”
   and not an equation, you cannot refer to the fields’ values directly by their
   names as you do from the equations in the calculated fields. In this case, you
   must use the getField operation and its val method.
 * Ex.
 *     ```wp-block-code
       if (getField('fieldname14').val(true) == '02')
       ```
   
 * Your function does not include the close key ` }`
 * Best regards.
 *  Thread Starter [pexel](https://wordpress.org/support/users/pexel/)
 * (@pexel)
 * [3 years ago](https://wordpress.org/support/topic/math-operation-problem/#post-16803789)
 * There should be no problem in the script right now, but it still doesn’t write
   results, I’ll go crazy 🙂
 *     ```wp-block-code
       function calculateGCD(a, b) {
         // Ensure positive values
         a = Math.abs(a);
         b = Math.abs(b);
   
         // Euclidean algorithm
         while (b !== 0) {
           var temp = b;
           b = a % b;
           a = temp;
         }
   
         return a;
       }
   
       var ebob;
   
       if (getField('fieldname14').val(true) === '02') {
         ebob = calculateGCD(getField('fieldname27').value, getField('fieldname26').value);
       }
       if (getField('fieldname14').val(true) === '03') {
         ebob = calculateGCD(getField('fieldname27').value, getField('fieldname26').value + getField('fieldname25').value);
       }
   
       // Output the result to HTML
       jQuery('#calculation-ebob').html(ebob);
       jQuery('.ebob-aciklama').html('En Büyük Ortak Bölen EBOB / OBEB:');
       jQuery('.ebob-sonuc').html(ebob + ' TL');
   
       // Return the value of ebob
       return ebob;
       ```
   
    -  This reply was modified 3 years ago by [pexel](https://wordpress.org/support/users/pexel/).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years ago](https://wordpress.org/support/topic/math-operation-problem/#post-16803806)
 * Hello [@pexel](https://wordpress.org/support/users/pexel/)
 * Your code has parser errors. Is the code an additional function in an “HTML Content”
   field, or it is an equation?
 * If it is an equation, it must be an auto-evaluated function: (function(){ Your
   code here })()
 * The equation cannot contain single-line comments (// ….). If you want to include
   comments in your code you must use block structure /* Your comment */
 * You are entering the function with parameters, but the parameters do not exist
   when you evaluate the equations.
 * Best regards.
 *  Thread Starter [pexel](https://wordpress.org/support/users/pexel/)
 * (@pexel)
 * [3 years ago](https://wordpress.org/support/topic/math-operation-problem/#post-16803866)
 * thanks, i made a little code mistake, i fixed it thanks to you.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Math Operation Problem’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [pexel](https://wordpress.org/support/users/pexel/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/math-operation-problem/#post-16803866)
 * Status: resolved