Skip to content

Commit

Permalink
feat: Add default level to the generateWord function
Browse files Browse the repository at this point in the history
- default level is set as easy
  • Loading branch information
sampathBlam committed May 7, 2020
1 parent 4b0694c commit eff7008
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const words = require('./words.json');

const MAX_WORD_INDEX = 50;
const wordlevels = ['easy', 'medium', 'hard']
const defaultLevel = 'easy';

const generateWord = (level) => {
if(!wordlevels.includes(level)){
if(level && !wordlevels.includes(level)){
return null;
}
const randomNumber = utils.generateRandomInt(MAX_WORD_INDEX);
return words[level][randomNumber];
return words[level || defaultLevel][randomNumber];
}

module.exports = {
Expand Down

0 comments on commit eff7008

Please sign in to comment.