• Resolved pexel

    (@pexel)


    I can’t print the result or what mistake am I making? I’m trying to set up a OBEB OKEK calculation scenario.

    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 1 year, 5 months ago by pexel.
    • This topic was modified 1 year, 5 months ago by pexel.
    • This topic was modified 1 year, 5 months ago by pexel.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @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.

    if (getField('fieldname14').val(true) == '02')

    Your function does not include the close key }

    Best regards.

    Thread Starter pexel

    (@pexel)

    There should be no problem in the script right now, but it still doesn’t write results, I’ll go crazy ??

    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 1 year, 5 months ago by pexel.
    Plugin Author codepeople

    (@codepeople)

    Hello @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

    (@pexel)

    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.