Holden G. Casey
Holden G. Casey

Reputation: 13

Why Is my code not outputting the string from the if statement?

Here is my code: https://plnkr.co/edit/HFyKq2JZipwAAST0iNAt?p=preview Why is it not outputting the result of the if statement to the tag with ID "WA" Here's the IF Statement separate from the code linked above:

if (demlean.WA <= 5 && demlean.WA >= -5) {
        if (demlean.WA > 0) {
          var lWA = "Tossup, Tilt D";
        } else if (demlean.WA < 0) {
          var lWA = "Tossup, Tilt R";
        } else {
          var lWA = "Absolute Tossup";
        }

      } else if (demlean.WA > 5) {
        if (demlean.WA <= 10) {
          var lWA = "Lean D";
        } else if (demlean.WA <= 17) {
          var lWA = "Likely D";
        } else {
          var lWA = "Safe D";
        }
      } else {
        if (demlean.WA >= -10) {
          var lWA = "Lean R";
        } else if (demlean.WA >= -17) {
          var lWA = "Likely R";
        } else {
          var lWA = "Safe R";
        }
 }
.... // more code

Upvotes: 1

Views: 71

Answers (3)

Ele
Ele

Reputation: 33726

Problem

  • The last closing curly brace is missing :-)

Solution

  • Add the missing curly brace :-)

var demlean = {
  WA: 5
};

if (demlean.WA <= 5 && demlean.WA >= -5) {
  if (demlean.WA > 0) {
    var lWA = "Tossup, Tilt D";
  } else if (demlean.WA < 0) {
    var lWA = "Tossup, Tilt R";
  } else {
    var lWA = "Absolute Tossup";
  }

} else if (demlean.WA > 5) {
  if (demlean.WA <= 10) {
    var lWA = "Lean D";
  } else if (demlean.WA <= 17) {
    var lWA = "Likely D";
  } else {
    var lWA = "Safe D";
  }
} else {
  if (demlean.WA >= -10) {
    var lWA = "Lean R";
  } else if (demlean.WA >= -17) {
    var lWA = "Likely R";
  } else {
    var lWA = "Safe R";
  }
}

console.log(lWA);

See? now your code runs as expected.

Upvotes: 0

MD Ruhul Amin
MD Ruhul Amin

Reputation: 4502

Okay finally I'm able to run your code, Here is the modification what I've done. First,

Uncaught ReferenceError: dDe is not defined
    at calc ((index):140)
    at submit ((index):153)
    at HTMLButtonElement.onclick ((index):167)

So I changed this line to DE: dDE,. Then another error

Uncaught ReferenceError: demlean is not defined
    at lean ((index):45)
    at calc ((index):146)
    at submit ((index):153)
    at HTMLButtonElement.onclick ((index):167)

demlean is a local variable. so i need to pass this to lean function.

    .....
    var geba;
    var tda;
    /* If Statement for determing lean in variable lSTATE */
    function lean(demlean) {
    .....
    .
    .
    .
    DE: dDE,
    MD: dMD,
    NY: dNY,
    VT: dVT,
    ME: dME,
    HI: dHI
  };
  // passing demlean here.
  lean(demlean);

Hope this help. Here is the updated code link: https://plnkr.co/edit/fGlSmDEWNEtKEZ7sLgUC?p=info

Upvotes: 1

Johannes
Johannes

Reputation: 67758

In the code you posted there is a closing } missing at the very end

Upvotes: 0

Related Questions