title: How to remove undefined returns in once() function (without changing previous function)
body: <p>I have two snippets of code, they differ in the definition of the add(y) function.  One uses console.log() (The original version) and one is modified to use return.  The second way I can get my prompt to pass, which is...</p>
  
  <blockquote>
    <p>Write a function once that accepts a callback as input and returns a function. When the returned function is called the first time, it should call the callback and return that output. If it is called any additional times, instead of calling the callback again it will simply return the output value from the first time it was called.</p>
  </blockquote>
  
  <p>How can I refactor the first code without modifying add(y) to achieve the desired result that is returned in the second code?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Challenge 4
  function addByX(x) {
    function add(y) {
      console.log(y + x);
    }
    return add;
  }
  
  var addByTwo = addByX(2);
  
  // now call addByTwo with an input of 1
  //addByTwo(1);
  // now call addByTwo with an input of 2
  //addByTwo(5);
  
  //Challenge 5
  function once(func) {
    var answer;
  
    function inner(x) {
      if (!answer) {
        answer = func(x);
        return answer;
      } else {
        return answer;
      }
    }
    return inner;
  }
  
  var onceFunc = once(addByTwo);
  
  // UNCOMMENT THESE TO TEST YOUR WORK!
  console.log(onceFunc(5)); //should log 7
  console.log(onceFunc(10)); //should log 7
  console.log(onceFunc(9001)); //should log 7</code></pre>
  </div>
  </div>
  </p>
  
  <p>SECOND CODE(works)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Challenge 4
  function addByX(x) {
    function add(y) {
      return y + x;
    }
    return add;
  }
  
  var addByTwo = addByX(2);
  
  // now call addByTwo with an input of 1
  //addByTwo(1);
  // now call addByTwo with an input of 2
  //addByTwo(5);
  
  //Challenge 5
  function once(func) {
    var answer;
  
    function inner(x) {
      if (!answer) {
        answer = func(x);
        return answer;
      } else {
        return answer;
      }
    }
    return inner;
  }
  
  var onceFunc = once(addByTwo);
  
  // UNCOMMENT THESE TO TEST YOUR WORK!
  console.log(onceFunc(5)); //should log 7
  console.log(onceFunc(10)); //should log 7
  console.log(onceFunc(9001)); //should log 7</code></pre>
  </div>
  </div>
  </p>