-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgreeting.js
More file actions
25 lines (21 loc) · 796 Bytes
/
greeting.js
File metadata and controls
25 lines (21 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
Write a command line application which prints a greeting message on the console using the function above.
- ex1. `$ node greeting.js Dale Seo KR` should print `Hello, Seo Dale!`
- ex2. `$ node greeting.js Dale Seo KR` should print `Hello, Dale Seo!`
*/
function getFullName(first, last, country) {
var eastCountries = ['KR', 'CH', 'JP'];
var westContrries = ['US', 'CA', 'UK'];
country = country.toUpperCase();
if (eastCountries.indexOf(country) > -1) {
return last + ' ' + first;
} else if (westContrries.indexOf(country) > -1) {
return first + ' ' + last;
} else {
throw new Error('Invalid country!');
}
}
var first = process.argv[2];
var last = process.argv[3];
var country = process.argv[4];
console.log('Hello, ' + getFullName(first, last, country) + '!');