title: How do you save the value of a randomly generated number for recalling in a different function?
body: <p>How do you save the output of a random number generator function to be recalled in a different function?</p>
  
  <p>For example, in the code below, I would be using the <code>function randNum()</code> to roll the dice and <code>return</code> the value of <code>w</code> to the <code>saveDiceNumber()</code> function as a variable.</p>
  
  <p>Then I would save the first value received from the <code>randNum()</code> function into the new variable <code>x</code> located in the <code>saveDiceNumber()</code> function. Then I would like to repeat the process for variables <code>y</code> and <code>z</code>, without losing the newly created value of <code>x</code>. </p>
  
  <p>So in essence, I would like to create a single function that uses the same random number generator to create 3 different variables and then recall the value of those variables without having to re-generate/re-roll random numbers.</p>
  
  <hr>
  
  <p>The random number generator function:</p>
  
  <pre><code>function randNum(){
      return Math.floor(Math.random()*6); 
  }
  </code></pre>
  
  <p>Function where RNG output should be saved:</p>
  
  <pre><code>function saveDiceNumber(){
      var w = randNum(); //roll the dice for the first permanent value
  
      var x = randNum(); //second output of dice
      var y = randNum(); //third output of dice
      var z = randNum(); //forth output of dice
  
      pickFruit(x);
      }
  </code></pre>
  
  <p>Where the output of <code>saveDiceNumber()</code> will be used:</p>
  
  <pre><code>   function pickFruit(letter){
  
         switch(letter){
         case(1):
         console.log("Apples");
         break;
         case(2):
         console.log("Pears");
         break;
         case(3):
         console.log("Bananas");
         break;
         case(4):
         console.log("Mangos");
         break;
         case(5):
         console.log("Pineapples");
         break;
         case(6):
         console.log("Avacados");
         break;
  }
  </code></pre>
  
  <p>Typing: <code>saveDiceNumber()</code> will console log different fruit every time, even though the function <code>pickFruit(x)</code> is the same. </p>
  
  <p>I need the value of the variable <code>x</code> to permanently equal to <code>=</code> the value generated by one usage of the <code>randNum()</code> function.</p>
  
  <p>So if I roll a 3, then <code>x</code> needs to be permanently equal to 3.</p>