dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Functions and Returns

  1. #1
    Join Date
    Oct 2013
    Posts
    11

    Functions and Returns

    Hey,

    I am having difficulty with this set of functions and returns:

    // Parameter is a number, and we do math with that parameter
    var timesTwo = function(number) {
    return number * 2;
    };

    //Call timesTwo here!
    var newNumber = function(name){
    return timesTwo;
    }
    console.log(newNumber);


    On line 7 I am supposed to call the function "timesTwo" with any parameter I want, however I keep getting an error saying I am not calling "timesTwo" function correctly.
    What am I doing wrong?

  2. #2
    Join Date
    Mar 2009
    Posts
    522
    //Call timesTwo here!
    var newNumber = timesTwo(7); //call the actual function remembering to "feed" it a number
    console.log(newNumber);

    //prints 14

    As you have the code written "newNumber" becomes a function, not a number and the single argument "name" performs no function at all.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles