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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question A better understanding of how this function works.

    Hi im completely new to coding but have enjoyed every moment I've started it. I have been doing the lessons for JavaScript on codecademy.com and was stumped on this function for like a half an hour. When I figured it out and passed the lesson I couldn't understand how I was getting the numbers I was getting from the function its self. Here is the code...



    var orangeCost = function (price)
    {
    var val = price * 5;
    console.log (val);
    };
    orangeCost (5)



    here are my Results...

    25
    25
    50

    And here was the Instructions...

    You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

    1. You want to declare a function that calculates the cost of buying 5 oranges.

    2. You then want to calculate the cost of the 5 all together.

    3. Write a function that does this called orangeCost().

    4. It should take a parameter that is the cost of an orange, and multiply it by

    5. It should log the result of the multiplication to the console.

    6. Call the function where oranges each cost 5 dollars.


    I'd Really appreciate a breakdown as to how this function is giving the results it is and if possible how the instructions match up with my results.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,112
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Quote Originally Posted by WHTphoenix View Post
    Hi im completely new to coding but have enjoyed every moment I've started it. I have been doing the lessons for JavaScript on codecademy.com and was stumped on this function for like a half an hour. When I figured it out and passed the lesson I couldn't understand how I was getting the numbers I was getting from the function its self. Here is the code...



    var orangeCost = function (price)
    {
    var val = price * 5;
    console.log (val);
    };
    orangeCost (5)



    here are my Results...

    25
    25
    50

    And here was the Instructions...

    You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

    1. You want to declare a function that calculates the cost of buying 5 oranges.

    2. You then want to calculate the cost of the 5 all together.

    3. Write a function that does this called orangeCost().

    4. It should take a parameter that is the cost of an orange, and multiply it by 5

    5. It should log the result of the multiplication to the console.

    6. Call the function where oranges each cost 5 dollars.


    I'd Really appreciate a breakdown as to how this function is giving the results it is and if possible how the instructions match up with my results.
    I put the number of the question line at the end of each of the function lines...

    Items 1-2 are just the definition and instructions for the problem.
    Code:
    var orangeCost = function (price) {  // Item #3
        var val = price * 5;             // Item #4
        console.log (val);               // Item #5
    };
    orangeCost (5)                       // Item #6


  •  

    Posting Permissions

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