Bootcamp
Search…
2.ICE.6: NPM, JSON File Storage

NPM

  1. 1.
    Clone the base Node repo.
  2. 2.
    Install the talk-like-a npm package and set it to talk like a Swedish chef.
  3. 3.
    Write an app such that a user can run the following program on the command line with any text and the app will output a result.
Note: If using import syntax, we will need to import talkLikeA as a default export first, before using talkLikeA.chef to convert our output. This is because talk-like-a was built using old export syntax that only supports default exports.

Sample Input

node index.js 'Hello! How are you today?'

Sample Output

Hellu! Hoo ere-a yuoo tudey? Bork Bork Bork!

jsonFileStorage

Roll Dice and Save Value

Write an app such that when the user types the roll command, the computer rolls a dice and records the role in a local JSON file data.json.

Sample Command

node index.js roll

Sample Output

You rolled 6.

Sample data.json

{
"rolls": [6]
}

Get Average Dice Roll

Update the app such that when the user types the average command, the computer outputs the average of all dice rolls so far.

Sample data.json

{
"rolls": [3, 3, 3]
}

Sample Command

node index.js average

Sample Output

Average is 3.

Most Rolled Dice Number

  1. 1.
    Update the app to keep a JS Object frequency tally in data.json that tracks how many times the computer rolled each dice number.
  2. 2.
    Maintain this tally by incrementing the relevant value whenever the program rolls a new dice.
  3. 3.
    Each time the computer rolls a dice, output the most frequently rolled dice after the current dice roll.

Sample data.json

{
"rolls": [3, 3, 3, ...],
"frequencies": {
"1": 4,
"2": 0,
"3": 6,
"4": 1,
"5": 1,
"6": 3
}
}

Sample Command

node index.js roll

Sample Output

You rolled 6.
The computer has rolled 3 the most times.