Skip to content

Commit

Permalink
Adding logic to handle 'no results found' by throwing an IF that catches
Browse files Browse the repository at this point in the history
a response of length 0
  • Loading branch information
rainrivas committed Jan 14, 2018
1 parent 523e0f0 commit d6aaeed
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ program
if (err) throw new Error(err);
var trimRes;
var results = JSON.parse(body).list;
if (results.length > 3) {
trimRes = results.slice(0, 3);
} else {
trimRes = results;
if (results.length === 0 ) {
console.log('No results were found, please try another phrase');
}
trimRes.forEach((result) => {
if (typeof (result.definition) !== undefined) {
console.log("=======================\n" + result.definition);
else {
if (results.length > 3) {
trimRes = results.slice(0, 3);
} else {
trimRes = results;
}
});
trimRes.forEach((result) => {
if (typeof (result.definition) !== undefined) {
console.log('=======================\n' + result.definition);
}
});
}
});
})
.parse(process.argv);

0 comments on commit d6aaeed

Please sign in to comment.