function randomData() {

    // use FS to read the random.txt file
    fs.readFile('./random.txt', 'utf8', function read(err, data) {

        if (err) {
            throw err;
        }

        // set a variable to stand for the text contents of the file
        var randomTxtCSV = data;

        // send random.txt file contents to csvArray(csv) to format data
        csvToArray(randomTxtCSV);

    });


    // function that formats the data from the random.txt file
    function csvToArray(csv) {

        // make the file data an Array, .split() at each new line
        randomTxtArray = csv.split('\n');
        // console.log(randomTxtArray);

        // Array that will hold all the individual {'command':'"mediaName"'} objects
        var objectArray = [];

        // Object structure for each {'command':'"mediaName"'} object
        var arrayObject = {};

        // loop through randomTxtArray ['command,"mediaName"', 'command,"mediaName"', ...]
        for (var i = 0; i < randomTxtArray.length; i++) {

            // .split() each element into its own two-element Array [ 'concert-this', '"Dead Can Dance"' ]
            var commandSubject = randomTxtArray[i].split(',');
            // console.log(commandSubject);

            // make a key variable out of the first element of the two-element Array
            var theKey = commandSubject[0];
            // console.log(theKey);

            // make a value variable out of the second element of the two-element Array
            // and strip off surrounding single or double quotes
            var theValue = commandSubject[1].replace(/['"]+/g, '');
            // console.log(theValue);

            // then take theKey and theValue, construct an Object, 
            // and push each Object into objectArray, which holds Object-ified data from random.txt
            objectArray.push({
                [theKey]: theValue
            });

        };

        // print the resulting objectArray to check it
        // console.log(objectArray);

        // then get a random number between 1 and the length of objectArray
        var randomNumber = Math.floor(Math.random() * objectArray.length) + 1;
        // console.log(randomNumber);

        // and use that random number to pick one object out of objectArray
        var randomObject = objectArray[randomNumber];
        // console.log(randomObject);

        // COMMAND: catch any input data errors in the command input data 
        // by replacing command with a hard-coded value
        if (randomObject === null || randomObject === undefined) {
            command = "concert-this";
        } else {
            command = Object.keys(randomObject).toString();
        }

        // MEDIANAME: catch any input data errors in the mediaName input data 
        // by replacing mediaName with a hard-coded value
        if (randomObject === null || randomObject === undefined) {
            mediaName = "Thievery Corporation";
        } else {
            mediaName = Object.values(randomObject).toString();
        }

        // and call the apiSelector function with input values now set
        apiSelector();
    };
}
// FUNCTION CALLED BY: node liri.js random
FUNCTION CALLED BY: node liri.js random
FUNCTION CALLED BY : node liri . js random
function randomData() {
    fs.readFile('./random.txt', 'utf8', function read(err, data) {
        if (err) {
            throw err;
        }
        var randomTxtCSV = data;
        csvToArray(randomTxtCSV);
    });
    function csvToArray(csv) {
        randomTxtArray = csv.split('\n');
        var objectArray = [];
        var arrayObject = {};
        for (var i = 0; i < randomTxtArray.length; i++) {
            var commandSubject = randomTxtArray[i].split(',');
            var theKey = commandSubject[0];
            var theValue = commandSubject[1].replace(/['"]+/g, '');
            objectArray.push({
                [theKey]: theValue
            });
        };
        var randomNumber = Math.floor(Math.random() * objectArray.length) + 1;
        var randomObject = objectArray[randomNumber];
        if (randomObject === null || randomObject === undefined) {
            command = "concert-this";
        } else {
            command = Object.keys(randomObject).toString();
        }
        if (randomObject === null || randomObject === undefined) {
            mediaName = "Thievery Corporation";
        } else {
            mediaName = Object.values(randomObject).toString();
        }
        apiSelector();
    };
}
function randomData ( ) { fs . readFile ( './random.txt' , 'utf8' , function read ( err , data ) { if ( err ) { throw err ; } var randomTxtCSV = data ; csvToArray ( randomTxtCSV ) ; } ) ; function csvToArray ( csv ) { randomTxtArray = csv . split ( '\n' ) ; var objectArray = [ ] ; var arrayObject = { } ; for ( var i = 0 ; i < randomTxtArray . length ; i ++ ) { var commandSubject = randomTxtArray [ i ] . split ( ',' ) ; var theKey = commandSubject [ 0 ] ; var theValue = commandSubject [ 1 ] . replace ( / ['"]+ / g , '' ) ; objectArray . push ( { [ theKey ] : theValue } ) ; } ; var randomNumber = Math . floor ( Math . random ( ) * objectArray . length ) + 1 ; var randomObject = objectArray [ randomNumber ] ; if ( randomObject === null || randomObject === undefined ) { command = "concert-this" ; } else { command = Object . keys ( randomObject ) . toString ( ) ; } if ( randomObject === null || randomObject === undefined ) { mediaName = "Thievery Corporation" ; } else { mediaName = Object . values ( randomObject ) . toString ( ) ; } apiSelector ( ) ; } ; }
FUNCTION CALLED BY: node liri.js random
FUNCTION CALLED BY : node liri . js random
// use FS to read the random.txt file // set a variable to stand for the text contents of the file // send random.txt file contents to csvArray(csv) to format data // function that formats the data from the random.txt file // make the file data an Array, .split() at each new line // console.log(randomTxtArray); // Array that will hold all the individual {'command':'"mediaName"'} objects // Object structure for each {'command':'"mediaName"'} object // loop through randomTxtArray ['command,"mediaName"', 'command,"mediaName"', ...] // .split() each element into its own two-element Array [ 'concert-this', '"Dead Can Dance"' ] // console.log(commandSubject); // make a key variable out of the first element of the two-element Array // console.log(theKey); // make a value variable out of the second element of the two-element Array // and strip off surrounding single or double quotes // console.log(theValue); // then take theKey and theValue, construct an Object,  // and push each Object into objectArray, which holds Object-ified data from random.txt // print the resulting objectArray to check it // console.log(objectArray); // then get a random number between 1 and the length of objectArray // console.log(randomNumber); // and use that random number to pick one object out of objectArray // console.log(randomObject); // COMMAND: catch any input data errors in the command input data  // by replacing command with a hard-coded value // MEDIANAME: catch any input data errors in the mediaName input data  // by replacing mediaName with a hard-coded value // and call the apiSelector function with input values now set