270: NODE

Use node.js to create a pure JavaScript Program

0. Come to class as there may be corrections, changes and additions.   Significant late penalty per day.
1. Use Node.js v 8.94 to create your code.
2. Follow these directions to SUBMIT a folder called "NODE" to the D2L dropbox.
3. Document your development environment with details. VS Code? Terminal? Extensions?
4. Comment! (guidelines)
         Rev. 2.0

         Create a complete node.js program.
         Need:
            node.js
            vs code - use it

         Use:
            NO global variables 

            npm install readline-sync               

            functions (at least these SEVEN)

               function startProgram() {
                  // main logic of the program
                  var fibs = []; // empty array
                  var maxnum = 50;
                  var usernum = getnum(maxnum);               
                  if (usernum !== -1) { // if user input is valid, proceed
                     out('\n\tUser entered: ' + usernum + '\n'); // echo number
                     out('\n\tFizzBuzz\n-------------------');
                     fizzbuzz(usernum);
                     fibb(usernum, fibs);
                     out('\n\tFibonacci\n-------------------');
                     printArray(fibs);
                     out('\n\tFibonacci Reversed\n----------------------------');
                     printArrayBack(fibs);
                  } 
                  else {
                     out('\n\tUser input error. Expected whole number between 2 and ' + maxnum);
                  }
               }               
               
               fizzbuzz( n )
                  numbers 1-n 
                  calculate and print (calls 'out()')
                     divisible by 3 - fizz
                     divisible by 5 - buzz
                     divisible by both 3 & 5 - fizzbuzz
                  no return

               fibb( n, arrayRef )
                  fill an array with first n fibbonacci numbers
                        0, 1, 1, 2, 3, 5, 8, 13, etc...
                  may 'hard code' first TWO numbers in array
                  return filled array
               
               printArray( arrayRef )
                  loops thru entire array
                  prints array one item at a time
                  calls 'out()' for each item in array
                  no return

               printArrayBack( arrayRef )
                  loops thru entire array in reverse
                  prints array one item at a time
                  calls 'out()' for each item in array
                  no return

               out( s )
                  outputs s, a string passed in
                  no return

               getnum ( max )        
                  var readline = require( 'readline-sync' );       
                  asks user for a number, n (see npm doc)  
                  parse input
                  check for NaN, null, undefined
                     return -1 on bad input
                  range check (1 thru max)
                     return -1 on bad input
                  if number ok
                     return number to caller

            EXAMPLE OUTPUT ==============================================================
            
               c:\!WyattWeb\!node>node ff
               Number? (2 thru 50): 5
               
                     User entered: 5
               
               
                     FizzBuzz
               -------------------
               1
               2
               fizz
               4
               buzz
               
                     Fibonacci
               -------------------
               1: 0
               2: 1
               3: 1
               4: 2
               5: 3
               
                     Fibonacci Reversed
               ----------------------------
               5: 3
               4: 2
               3: 1
               2: 1
               1: 0
            
            EXAMPLE OUTPUT ==============================================================
            
               c:\!WyattWeb\!node>node ff
               Number? (2 thru 50): doggy
               
                     User input error. Expected whole number between 2 and 50
               
               c:\!WyattWeb\!node>node ff
               Number? (2 thru 50): 1
               
                     User input error. Expected whole number between 2 and 50
               
               c:\!WyattWeb\!node>node ff
               Number? (2 thru 50): 55
               
                     User input error. Expected whole number between 2 and 50
            
            
            EXAMPLE OUTPUT ==============================================================

               c:\!WyattWeb\!node>node ff
               Number? (2 thru 50): 15

                     User entered: 15


                     FizzBuzz
               -------------------
               1
               2
               fizz
               4
               buzz
               fizz
               7
               8
               fizz
               buzz
               11
               fizz
               13
               14
               fizzbuzz

                     Fibonacci
               -------------------
               1: 0
               2: 1
               3: 1
               4: 2
               5: 3
               6: 5
               7: 8
               8: 13
               9: 21
               10: 34
               11: 55
               12: 89
               13: 144
               14: 233
               15: 377

                     Fibonacci Reversed
               ----------------------------
               15: 377
               14: 233
               13: 144
               12: 89
               11: 55
               10: 34
               9: 21
               8: 13
               7: 8
               6: 5
               5: 3
               4: 2
               3: 1
               2: 1
               1: 0
         

Submit folder called 'NODE' with ALL files (including 'vs code' and 'node' files) to D2L