Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
20 changes: 20 additions & 0 deletions lib/howdy.js
Original file line number Diff line number Diff line change
@@ -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}`;
};
28 changes: 28 additions & 0 deletions test/howdy-test.js
Original file line number Diff line number Diff line change
@@ -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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great variable name. :)

});
});
});