diff --git a/index.js b/index.js new file mode 100644 index 0000000..6102f36 --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +'use strict'; + +const welcome = require('./lib/howdy.js'); + +if (process.argv.length < 3) throw new Error('please enter a name!'); + +if (process.argv.length === 3) welcome.greeting(process.argv[2]); + +if (process.argv.length > 3) welcome.multipleGreetings(process.argv); diff --git a/lib/howdy.js b/lib/howdy.js new file mode 100644 index 0000000..4441aef --- /dev/null +++ b/lib/howdy.js @@ -0,0 +1,20 @@ +'use strict'; + +module.exports = exports = {}; + +exports.greeting = function(name) { + if (arguments.length === 0) throw new Error('no name given'); + console.log(`What's up, ${name}?!`); + return `hello ${name}`; +}; + +exports.multipleGreetings = function(termInput) { + let names = termInput.slice(2); + let logMessage = " "; + logMessage += names.slice(0, -1).join(', '); + logMessage += (' and '); + logMessage += names.slice(-1).join(''); + logMessage += ('!'); + console.log(`Hey there ${logMessage}`); + return `Hey there ${logMessage}`; +}; diff --git a/test/howdy-test.js b/test/howdy-test.js new file mode 100644 index 0000000..557d9fe --- /dev/null +++ b/test/howdy-test.js @@ -0,0 +1,28 @@ +'use strict'; + +const assert = require('assert'); +const howdy = require('../lib/howdy.js'); +// const hackyMessageVariable = howdy.multipleGreetings.logMessage; +// console.log(hackyMessageVariable); + +describe('Howdy Module', function() { + describe('#greeting', function() { + it(`should return hello ${process.argv[2]}`, function() { + let printout = howdy.greeting(process.argv[2]); + assert.ok(printout === `hello ${process.argv[2]}`, 'incorrect result'); + }); + }); + describe('#greeting', function() { + it('Should result in error from missing input', function() { + assert.throws(function() { + howdy.greeting(); + }, 'Error not thrown for empty input'); + }); + }); + describe('#multipleGreetings', function() { + it(`should return all names entered in command line`, function() { + let printout = howdy.multipleGreetings(process.argv); + assert.ok(printout === `Hey there ${hackyMessageVariable}`, 'not quite right'); + }); + }); +});