What Am I doing Wrong?

Discussion in 'Gaming' started by Y0urWaifuisTrash, Jan 16, 2014.

  1. So, I've been messing around with JavaScript, and I have a couple lines that are returning errors. Would you be able to tell me what I'm doing wrong?
    Code:
    var creditCheck = function (income) {
        if (creditCheck) >= 99 {
        return "creditTrue";
        } else; {
            return "creditFalse"; }};
    Code:
    Errors:
    LINE 4: Expected an Identifier and instead saw '>='
    Missing ';' before statement (what?!?)
    LINE 6: Expected an Identifier and instead saw 'else'
  2. The >= 99 should be inside the parentheses and there should be no semicolon( ; ) after else.
  3. Your entire "if" conditional should be in parentheses:
    Code:
    if (creditCheck >= 99) {...
    "else" should not have a semicolon, it is like the "if" statement.

    See more here.
    mba2012 likes this.
  4. thanks :rolleyes: I'm really good at this... :p
  5. It's always confusing when you first start programming :p
  6. oh, great. I'm supposed to use multiple calls on creditCheck, how, just, how >.<
    Code:
    var creditCheck = function (income) {
        if (creditCheck >= 100) {
        return "creditTrue";
        } else {
            return "creditFalse"; }};
        creditCheck(75)
        creditCheck(125)
        creditCheck(100)
    What I want to be the output:
    Code:
    "creditFalse"
    "creditTrue"
    "creditTrue"
    What I get instead:
    Code:
    "creditFalse"
  7. Shouldn't there be a semicolon after each time you call the function?
    Code:
    creditCheck(75);
    creditCheck(125);
    creditCheck(100);
  8. still not fixing it >.< (and I figured that out literally one second before i read your message, lol xD)
  9. I enjoy looking at code and learning it, but I absolutely HATE writing code xD I have to do it all the time in Robotics and they tell me its "simple coding", yeah... no.
    oremia likes this.
  10. hahaha, It's actually pretty simple if you use a website that runs you through it ;P (It's so hard tho right now >.< Functions...)
  11. Just to help,
  12. Oh, I see something. Try removing the semicolon after the function. And just to make your code easier to read, lay it out like this:
    Code:
    var creditCheck = function (income) {
        if (creditCheck >= 100) {
        return "creditTrue";
        } else {
            return "creditFalse"; }};
        creditCheck(75)
        creditCheck(125)
        creditCheck(100)var creditCheck = function (income) {
        if (creditCheck >= 100) {
        return "creditTrue";
        } else {
            return "creditFalse";
        }
    }
        creditCheck(75);
        creditCheck(125);
        creditCheck(100);
    I've noticed a few other things that might be messing it up a bit, but I'll have to get back to you about those.
  13. lol, I think you duplicated the code xD
    mba2012 likes this.
  14. Ok, done a bit of research and it looks like you're making your function a variable or something like that. So what you need to do is create a function, without assigning it to a variable.

    Code:
    function creditCheck(income) {
    //empty function
    }
    That code gives you an empty function. What you now need to do is add your if-else statement.
    Code:
    if(income >= 100) {
    return "creditTrue";
    } else {
    return "creditFalse";
    }
    
    //Add the above to your function
    
    function creditCheck(income) {
      if(income >= 100) {
          return "creditTrue";
      } else {
          return "creditFalse";
      }
    }
    Once that function is complete, you can call it.
    Code:
    creditCheck(75);
    creditCheck(125);
    creditCheck(100);
    Pab10S likes this.
  15. I want to get into coding but no idea...
    What would these codes be used for? ( Probably dumb question )
  16. I'm not sure exactly what this specific code does. Javascript is mainly used to add functionality to games and websites.
    samsimx likes this.
  17. This code is supposed to find the value of creditCheck, then if it is greater than or equal to 100, print "You earn a lot of money! You qualify for a credit card." otherwise, print "Alas you do not qualify for a credit card. Capitalism is cruel like that.". (By the way, changing my function between local/global doesn't seem to help ; - ;) *begins to google*
  18. You used the rewritten function that I supplied? Because if that doesn't work, then I have no idea what is wrong :/
  19. I'm honestly considering skipping this lesson, I feel like it might be broken :/ will do some deeper research tho ; - ;
  20. Are you on codeacademy.com? This looks familiar.