Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question If else Statement with return, What's Wrong with the code below

    Dear Folks,
    I am a new to javaScript, so i was doing some homework and there is this example or quiz i can't able to solve, i tried to see what's my mistake but it doesn't seems it has one but actually it dose.

    below is the code please help me out thanks & regard

    var creditCheck = function (income)
    if (income > === 100)
    {
    return "You earn a lot of money! You qualify for a credit card.";
    }
    else
    {
    return "Alas you do not qualify for a credit card. Capitalism is cruel like that.";
    }
    var creditCheck(75);

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    The function, itself, isn't encapsulated within brackets. Also, you can't declare a variable twice (you have "var creditCheck" and "var creditCheck(75)").
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    jmenonjava (03-21-2013)

  • #3
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    "> ===" also isn't valid syntax.

  • Users who have thanked Airblader for this post:

    jmenonjava (03-21-2013)

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by WolfShade View Post
    Also, you can't declare a variable twice (you have "var creditCheck" and "var creditCheck(75)").
    For the second one, he must have meant to call the function, so var shouldn't be there.
    Code:
    creditCheck(75);

  • Users who have thanked glenngv for this post:

    jmenonjava (03-21-2013)

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by glenngv View Post
    For the second one, he must have meant to call the function, so var shouldn't be there.
    Code:
    creditCheck(75);
    Presumably alert (creditCheck(75)); as the message is what is returned.

    The function needs to be enclosed in braces { and }, and not brackets which are ( and ).

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    jmenonjava (03-21-2013)

  • #6
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    5
    Thanked 0 Times in 0 Posts
    First I would like to thank you all you guys nice comment, I have learned from it also not yet therefore blow I will explain what I want to do with the code. If itís possible tell me which areas that I make a mystic and how to solve it.
    The idea is I m going to write a function that takes a persons income as parameter, inside the function I will use if / else statement, I want the function to check whether many different peopleís income qualify for them for a creditcard.
    where if the income is greater than or equal to 100 , I want the computer to return You earn a lot of money! You qualify for a credit card, but if itís less than 100 I want the computer to return, Alas you do not qualify for a credit card. Capitalism is cruel like that.
    And the end I will call the function with passing any income and regarding the income I put it will give me the return.


    var creditCheck = function (income)
    ({if income >=== 100}
    {return "You earn a lot of money! You qualify for a credit card."
    };else
    {return "Alas you do not qualify for a credit card. Capitalism is cruel like that."
    };
    creditCheck(75);

  • #7
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    The function, itself, isn't encapsulated within brackets. Also, you can't declare a variable twice (you have "var creditCheck" and "var creditCheck(75)").
    First I would like to thank you all you guys nice comment, I have learned from it also not yet therefore blow I will explain what I want to do with the code. If itís possible tell me which areas that I make a mystic and how to solve it.
    The idea is I m going to write a function that takes a persons income as parameter, inside the function I will use if / else statement, I want the function to check whether many different peopleís income qualify for them for a creditcard.
    where if the income is greater than or equal to 100 , I want the computer to return You earn a lot of money! You qualify for a credit card, but if itís less than 100 I want the computer to return, Alas you do not qualify for a credit card. Capitalism is cruel like that.
    And the end I will call the function with passing any income and regarding the income I put it will give me the return.


    var creditCheck = function (income)
    ({if income >=== 100}
    {return "You earn a lot of money! You qualify for a credit card."
    };else
    {return "Alas you do not qualify for a credit card. Capitalism is cruel like that."
    };
    creditCheck(75);

  • #8
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    4
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    For the second one, he must have meant to call the function, so var shouldn't be there.
    Code:
    creditCheck(75);
    First I would like to thank you all you guys nice comment, I have learned from it also not yet therefore blow I will explain what I want to do with the code. If itís possible tell me which areas that I make a mystic and how to solve it.
    The idea is I m going to write a function that takes a persons income as parameter, inside the function I will use if / else statement, I want the function to check whether many different peopleís income qualify for them for a creditcard.
    where if the income is greater than or equal to 100 , I want the computer to return You earn a lot of money! You qualify for a credit card, but if itís less than 100 I want the computer to return, Alas you do not qualify for a credit card. Capitalism is cruel like that.
    And the end I will call the function with passing any income and regarding the income I put it will give me the return.


    var creditCheck = function (income)
    ({if income >=== 100}
    {return "You earn a lot of money! You qualify for a credit card."
    };else
    {return "Alas you do not qualify for a credit card. Capitalism is cruel like that."
    };
    creditCheck(75);

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Sounds like homework! You have not paid very much attention to the advice offered by previous contributors

    Code:
    <script type = "text/javascript">
    
    var crchk = function creditCheck (income) {
    if (income >= 100) {
    return "You earn a lot of money! You qualify for a credit card."
    }
    else {
    return "Alas you do not qualify for a credit card. Capitalism is cruel like that."
    }
    }
    
    alert (crchk(75)); 
    
    </script>

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    jmenonjava (03-21-2013)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •