Skip to content

Commit

Permalink
Implement random word generator
Browse files Browse the repository at this point in the history
- Add 50 words each for easy, medium and hard levels
- Generate a random int
- Use it to pick a random word
- Return null if the input level is incorrect
  • Loading branch information
sampathBlam committed May 7, 2020
1 parent 593c147 commit 4b0694c
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const utils = require('./utils');
const words = require('./words.json');

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

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

module.exports = {
generateWord
}
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "pic-word-gen",
"version": "1.0.0",
"description": "A word generator for a pictionary game",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sampathBlam/pic-word-gen.git"
},
"keywords": [
"pic",
"pic-word"
],
"author": "Sampath Kumar Krishnan <sampathblam@users.noreply.github.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/sampathBlam/pic-word-gen/issues"
},
"homepage": "https://github.com/sampathBlam/pic-word-gen#readme"
}
3 changes: 3 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.generateRandomInt = (max) => {
return Math.floor(Math.random() * max);
}
158 changes: 158 additions & 0 deletions words.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"easy": [
"Scissors",
"Point",
"Star",
"Tree",
"Airplane",
"Tail",
"Basketball",
"Mouth",
"Telephone",
"Chin",
"Jar",
"Smile",
"Cheek",
"Ear",
"Drum",
"Room",
"Turtle",
"Wings",
"Doll",
"Bird",
"Spider",
"Hopscotch",
"Happy",
"Baby",
"Monkey",
"Pig",
"Jump",
"Crayon",
"Arm",
"Arm",
"Rabbit",
"Book",
"Camera",
"Rock",
"Chicken",
"Robot",
"Drink",
"Balloon",
"Kangaroo",
"Clap",
"Baseball",
"Milk",
"Icecream",
"Circle",
"Book",
"Sneeze",
"Dog",
"Flower",
"Pillow",
"Tree"
],
"medium": [
"Beg",
"Rollerblade",
"Summer",
"Cow",
"Fang",
"Table tennis",
"Snowball",
"Guitar",
"Alarm",
"Cape",
"Bird",
"Saddle",
"Rain",
"Bike",
"Roof",
"Blind",
"Hoop",
"Violin",
"Coil",
"Goldfish",
"Frankenstein",
"Stairs",
"Dog",
"String",
"Fetch",
"Cage",
"Mailbox",
"Spider man",
"Puppet",
"Penguin",
"Shovel",
"Popcorn",
"Butter",
"Trumpet",
"Haircut",
"Shopping trolley",
"Lipstick",
"Soap",
"Hula",
"Mop",
"Money",
"Food",
"Glue",
"Banana",
"Hot",
"See-saw",
"Jellyfish",
"Scarf",
"Table tennis",
"Snowball"
],
"hard": [
"Frankenstein",
"Sand",
"Year",
"Stain",
"Vest",
"Swordfish",
"Pizza",
"Softball",
"Party",
"Wrench",
"Hair",
"Spine",
"Beetle",
"Trip",
"Gym",
"Sip",
"Torch",
"Cowboy",
"Carrot",
"Spider web",
"Beggar",
"Lung",
"Basket",
"Flamingo",
"Cuff",
"Dryer",
"Blinds",
"Brain",
"Business",
"Eraser",
"Volcano",
"Whisk",
"Funny",
"Quicksand",
"Trap",
"Sheet",
"Small",
"Mouse",
"Poison",
"Washing",
"Marble",
"Nightmare",
"Vegetable",
"Anger",
"Knot",
"Badge",
"Cramp",
"Doghouse",
"Mirror",
"Softball"
]
}

0 comments on commit 4b0694c

Please sign in to comment.