Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Like Tree2Likes

Thread: Need some assistance

  1. #1
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times

    Need some assistance

    I am just going over some of the things i learned on code academy and i found a lesson where i was asked to create a function to calculate the cost of oranges.. I got the answer correct, but it is displaying 3 numbers and I'm not sure if that is suppose to happen that way? Is this right? or did Code Academy excuse something that i should be aware of? This just seems like it should only output 25

    Attached Images Attached Images
    Last edited by Vapr_Arts; Feb 25th, 2014 at 03:47 PM.

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Try this:
    Code:
    var orangeCost = function(price){
    return price * 5;
    }
    console.log(orangeCost(5));
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    Quote Originally Posted by Ronald Roe View Post
    Try this:
    Code:
    var orangeCost = function(price){
    return price * 5;
    }
    console.log(orangeCost(5));
    That came back as incorrect...

    I got the lesson correct when I did it, just looking back at it now it doesn't seem like it would display:

    25
    25
    50

    Shouldn't it just display 50? Did the lesson teach me an inefficient way of doing something? I mean the lesson is done and I understand the gist of it, just stuck on why id logged 25 twice and then 50 so i can't say i fully understand it

  5. #4
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    I think it's because you declared the variable orangeCost inside of the function that was referenced by the variable orangeCost. I would have done it like this:
    Code:
    function orangeCost (input) {
      if (!isNaN (input)) {return input * 5;}
    }
    var priceOf5 = orangeCost(5);
    console.log(priceOf5);
    That way, I could use the price function for other purpose.

    I'm also assuming they taught you what isNaN is.
    Last edited by TheGAME1264; Feb 25th, 2014 at 07:29 PM. Reason: Edit? What edit? I didn't edit nuthin'.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  6. #5
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by TheGAME1264 View Post
    I'm also assuming they taught you what isNaN is.
    I've been that far in the lessons. They haven't gone over isNaN yet.

    Also, the function has to be called orangeCost. I think Vapr's is failing because he's assigning the function's name as a variable inside the function (though, wouldn't the variable's scope negate that problem?).

    Mine is probably failing because it isn't formatted the way they are specifying for the lesson. I love Codecademy. Their approach is the only way I've ever been able to successfully learn JS or any other scripting language. I can definitely see the major flaw in their methods, though. I tested my script in Chrome's console, and it works without a hitch, but because it isn't done the way the lesson wants it, it's somehow wrong.

    Vapr: which lesson is that?
    TheGAME1264 likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  7. #6
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    But...that's what the function said...really...for true...it did.

    I haven't used Code Academy, but I'd probably get pissed off and either break the site, break my computer, or break the people that built it if that's their logic.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  8. #7
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Ugh. I messed with it. They want you to do the math inside the console.log line, like so:
    Code:
    var orangeCost = function(price){
        console.log(price * 5);
    }
    orangeCost(5);
    And before you ask, Cole, the difference here is that he wrote a perfectly valid script that their finnicky program doesn't want to take.
    If you weren't going to ask, well there's the answer anyway.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  9. #8
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    I asked The Iron Sheik what he thought about this Code Academy thing.

    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  10. #9
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by TheGAME1264 View Post
    I haven't used Code Academy, but I'd probably get pissed off and either break the site, break my computer, or break the people that built it if that's their logic.
    Such is why I eventually broke out on my own with learning. Their approach "breaks the seal", or better put gives you that "Aha!" moment. After that, once you've reached that point, it gets annoying quick. Writing a perfectly well constructed function that works even in their editor only to have it fail because it isn't their way...frustrating.
    TheGAME1264 likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  11. #10
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    Quote Originally Posted by Ronald Roe View Post
    I've been that far in the lessons. They haven't gone over isNaN yet.

    Also, the function has to be called orangeCost. I think Vapr's is failing because he's assigning the function's name as a variable inside the function (though, wouldn't the variable's scope negate that problem?).

    Mine is probably failing because it isn't formatted the way they are specifying for the lesson. I love Codecademy. Their approach is the only way I've ever been able to successfully learn JS or any other scripting language. I can definitely see the major flaw in their methods, though. I tested my script in Chrome's console, and it works without a hitch, but because it isn't done the way the lesson wants it, it's somehow wrong.

    Vapr: which lesson is that?
    Its in the Intro to functions in JS section..its 6/13

    I have the answer correct in their logic.. I was able to go on from there with what i originally put. I haven't been on there in awhile and so i wanted to refresh what i had already done before continuing. When I got to this lesson it was still correct, but the answer did not seem correct to me? I would assume that you would only want one answer to be sent back when in my case (and the correct answer in their eyes) sends back 3 numbers. Id assume that this would be a problem in real world situations. Like Ron said they are very picky with what they accept as the correct code, for it to feel wrong to me i am just surprised it is accepted..


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com