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
10 changes: 10 additions & 0 deletions lab-megan/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const greet = require('./lib/greetings.js');

process.argv.forEach((val, index) => {
console.log(`${index}: ${val}`);
});

greet.sayHello('Scott');
greet.sayGoodbye();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Glad to see you used process.argv[2] for the bonus!

Another way you could have implemented this was to attach another method onto the exports object in greetings.js. This method could have a variable set to process.argv[2] that could be passed as an argument which would dynamically generate a name for you. You could then invoke that method on index.js, similarly to how you are already invoking the others :)

12 changes: 12 additions & 0 deletions lab-megan/lib/greetings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

module.exports = exports = {};

exports.sayHello = function(theName) {
if (arguments.length === 0) throw new Error('No name was given.');
return(`Hello, ${theName}.`);
};

exports.sayGoodbye = function() {
return('Goodbye, it was nice to meet you.');
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work!

21 changes: 21 additions & 0 deletions lab-megan/test/greetings-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const greet = require('../lib/greetings.js');

const assert = require('assert');

describe('Greet Module', function () {
describe('#sayHello', function() {
it('should return Hello, Scott.', function () {
var result = greet.sayHello('Scott');
assert.ok(result === 'Hello, Scott.', 'Not equal to Hello, Scott.');
});
});

describe('#sayGoodbye', function() {
it('should return Goodbye, it was nice to meet you.', function() {
var goodbye = 'Goodbye, it was nice to meet you.';
assert.ok(goodbye === 'Goodbye, it was nice to meet you.', 'Not equal to Goodbye, it was nice to meet you.');
});
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't forget to throw in some error handling to account for the possibility of no name being passed in. You'll want to make sure to also have tests to take care of this, this could be handled in another it block.