function "kal" and "getsign" not functioning.

    function kal (ta) {
    var xy;
    var x1 ; 
    var x2; 
    var x3; 
    var x4;
           if (xy==1) {x1=0; x2=1; x3=1; x4=1;}
    else if  (xy==2) {x1=1; x2=0; x3=1; x4=0;}
    else if  (xy==3) {x1=0; x2=1; x3=0; x4=1;}
    else if  (xy==4) {x1=1; x2=1; x3=1; x4=1;}
    else if  (xy==5) {x1=0; x2=0; x3=1; x4=0;}
    else if  (xy==6) {x1=0; x2=1; x3=1; x4=0;}
    else if  (xy==7) {x1=1; x2=1; x3=1; x4=0;}
    else if  (xy==8) {x1=1; x2=0; x3=1; x4=1;}
    else if  (xy==9) {x1=1; x2=1; x3=0; x4=1;}
    else if  (xy==10) {x1=0; x2=0; x3=1; x4=1;}
    else if  (xy==11) {x1=1; x2=1; x3=0; x4=0;}
    else if  (xy==12) {x1=0; x2=0; x3=0; x4=1;}
    else if  (xy==13) {x1=0; x2=1; x3=0; x4=0;}
    else if  (xy==14) {x1=1; x2=0; x3=0; x4=0;}
    else if  (xy==15) {x1=1; x2=0; x3=0; x4=1;}
    else if  (xy==16) {x1=0; x2=0; x3=0; x4=0;}
    this.xa = x1;
    this.xb = x2;
    this.xc = x3;
    this.xd = x4;
    return this;
    }
    xaxa = kal(as)
    w1 = xaxa.xa

    xbxb =kal(bs)
    w2 =xbxb.xa

    xcxc =kal(cs)
    w3 = xcxc.xa

    xdxd = kal(ds)
    w4 = xdxd.xa

      function getsign(w1, w2, w3, w4) {
      var sa;
      var w1;
      var w2;
      var w3;
      var w4;
       if  (w1==0 && w2==1 && w3==1 && w4==1) {sa = 1};
      if  (w1==1 && w2==0 && w3==1 && w4==0) {sa = 2};
      if  (w1==0 && w2==1 && w3==0 && w4==1) {sa = 3};
      if  (w1==1 && w2==1 && w3==1 && w4==1) {sa = 4};
      if  (w1==0 && w2==0 && w3==1 && w4==0) {sa = 5};
      if  (w1==0 && w2==1 && w3==1 && w4==0) {sa = 6};
      if  (w1==1 && w2==1 && w3==1 && w4==0) {sa = 7};
      if  (w1==1 && w2==0 && w3==1 && w4==1) {sa = 8};
      if  (w1==1 && w2==1 && w3==0 && w4==1) {sa = 9};
      if  (w1==0 && w2==0 && w3==1 && w4==1) {sa = 10};
      if  (w1==1 && w2==1 && w3==0 && w4==0) {sa = 11};
      if  (w1==0 && w2==0 && w3==0 && w4==1) {sa = 12};
      if  (w1==0 && w2==1 && w3==0 && w4==0) {sa = 13};
      if  (w1==1 && w2==0 && w3==0 && w4==0) {sa = 14};
      if  (w1==1 && w2==0 && w3==0 && w4==1) {sa = 15};
     if   (w1==0 && w2==0 && w3==0 && w4==0) {sa = 16};
     return sa;
     }
    sign = getsign(w1, w2, w3, w4)

function kal (ta) {
var xy;
var x1 ; 
var x2; 
var x3; 
var x4;
       if (xy==1) {x1=0; x2=1; x3=1; x4=1;}
else if  (xy==2) {x1=1; x2=0; x3=1; x4=0;}
else if  (xy==3) {x1=0; x2=1; x3=0; x4=1;}
else if  (xy==4) {x1=1; x2=1; x3=1; x4=1;}
else if  (xy==5) {x1=0; x2=0; x3=1; x4=0;}
else if  (xy==6) {x1=0; x2=1; x3=1; x4=0;}
else if  (xy==7) {x1=1; x2=1; x3=1; x4=0;}
else if  (xy==8) {x1=1; x2=0; x3=1; x4=1;}
else if  (xy==9) {x1=1; x2=1; x3=0; x4=1;}
else if  (xy==10) {x1=0; x2=0; x3=1; x4=1;}
else if  (xy==11) {x1=1; x2=1; x3=0; x4=0;}
else if  (xy==12) {x1=0; x2=0; x3=0; x4=1;}
else if  (xy==13) {x1=0; x2=1; x3=0; x4=0;}
else if  (xy==14) {x1=1; x2=0; x3=0; x4=0;}
else if  (xy==15) {x1=1; x2=0; x3=0; x4=1;}
else if  (xy==16) {x1=0; x2=0; x3=0; x4=0;}
this.xa = x1;
this.xb = x2;
this.xc = x3;
this.xd = x4;
return this;
}
xaxa = kal(as)
w1 = xaxa.xa

xbxb =kal(bs)
w2 =xbxb.xa

xcxc =kal(cs)
w3 = xcxc.xa

xdxd = kal(ds)
w4 = xdxd.xa

  function getsign(w1, w2, w3, w4) {
  var sa;
  var w1;
  var w2;
  var w3;
  var w4;
   if  (w1==0 && w2==1 && w3==1 && w4==1) {sa = 1};
  if  (w1==1 && w2==0 && w3==1 && w4==0) {sa = 2};
  if  (w1==0 && w2==1 && w3==0 && w4==1) {sa = 3};
  if  (w1==1 && w2==1 && w3==1 && w4==1) {sa = 4};
  if  (w1==0 && w2==0 && w3==1 && w4==0) {sa = 5};
  if  (w1==0 && w2==1 && w3==1 && w4==0) {sa = 6};
  if  (w1==1 && w2==1 && w3==1 && w4==0) {sa = 7};
  if  (w1==1 && w2==0 && w3==1 && w4==1) {sa = 8};
  if  (w1==1 && w2==1 && w3==0 && w4==1) {sa = 9};
  if  (w1==0 && w2==0 && w3==1 && w4==1) {sa = 10};
  if  (w1==1 && w2==1 && w3==0 && w4==0) {sa = 11};
  if  (w1==0 && w2==0 && w3==0 && w4==1) {sa = 12};
  if  (w1==0 && w2==1 && w3==0 && w4==0) {sa = 13};
  if  (w1==1 && w2==0 && w3==0 && w4==0) {sa = 14};
  if  (w1==1 && w2==0 && w3==0 && w4==1) {sa = 15};
 if   (w1==0 && w2==0 && w3==0 && w4==0) {sa = 16};
 return sa;
 }
sign = getsign(w1, w2, w3, w4)

Dani AI

Generated

Short diagnosis (ties to ): the immediate runtime errors come from calling kal(as) where as (and bs, cs, ds) are never defined, and from kal never using its ta parameter (it declares xy but never assigns xy = ta). The duplicate function blocks in the post only add confusion — the last function kal(...) wins. Also avoid returning this from a factory-style function (that mutates the global object unless called with new), and remove misleading/unused declarations inside getsign (declaring var w1,w2,... inside a function that receives those as parameters is redundant and confusing).

Concrete fixes and best practices

  • At the top of kal assign xy = Number(ta) (or use const xy = ta) so the branch logic runs.
  • Return a plain object (e.g. { xa: x1, xb: x2, xc: x3, xd: x4 }) instead of this.
  • Make sure the caller passes defined values (e.g. var as = 3; xaxa = kal(as);).
  • In getsign do not redeclare parameter names; validate inputs and use a single if/else if chain or a lookup to ensure only one match.
  • Use strict mode ('use strict') during debugging so missing globals throw early.

Minimal, safe pattern to apply (no full pattern list repeated here — use the mapping already in the thread inside kal):

function kal(ta){
  const xy = Number(ta);
  // assign x1..x4 based on xy (use switch or a patterns array)
  return { xa: x1, xb: x2, xc: x3, xd: x4 };
}

function getsign(w1,w2,w3,w4){
  if ([w1,w2,w3,w4].some(v=> typeof v === 'undefined')) return null;
  for (let i=1;i<=16;i++){
    const p = kal(i);
    if (p.xa===w1 && p.xb===w2 && p.xc===w3 && p.xd===w4) return i;
  }
  return null;
}

Troubleshooting checklist

  • Look at the console for ReferenceError: as is not defined and fix the caller variables.
  • If xaxa is undefined, kal probably returned this or failed—inspect kal early with console.log(xy).
  • Prefer a lookup table or switch (as suggested) for maintainability; avoid ad-hoc globals.

Recommended Answers

All 2 Replies

Look to the console: "as" is not defined (line 29 and 95), function in parameter "ta" not used inside function.

Why you do not use a switch? It would be more convenient here:

function kal(ta){
    var xy=ta,x1,x2,x3,x4;
    switch(xy){
        case 1: x1=0; x2=1; x3=1; x4=1; break;
        case 2: x1=1; x2=0; x3=1; x4=0; break;
        case 3: x1=0; x2=1; x3=0; x4=1; break;
        case 4: x1=1; x2=1; x3=1; x4=1; break;
        case 5: x1=0; x2=0; x3=1; x4=0; break;
        case 6: x1=0; x2=1; x3=1; x4=0; break;
        case 7: x1=1; x2=1; x3=1; x4=0; break;
        case 8: x1=1; x2=0; x3=1; x4=1; break;
        case 9: x1=1; x2=1; x3=0; x4=1; break;
        case 10: x1=0; x2=0; x3=1; x4=1; break;
        case 11: x1=1; x2=1; x3=0; x4=0; break;
        case 12: x1=0; x2=0; x3=0; x4=1; break;
        case 13: x1=0; x2=1; x3=0; x4=0; break;
        case 14: x1=1; x2=0; x3=0; x4=0; break;
        case 15: x1=1; x2=0; x3=0; x4=1; break;
        case 16: x1=0; x2=0; x3=0; x4=0; break;
    }
    this.xa = x1;
    this.xb = x2;
    this.xc = x3;
    this.xd = x4;
    return this;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.