Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active May 21, 2019 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisonmalone/bf5acdce12ac6ced98a76fcaa0a7a7ca to your computer and use it in GitHub Desktop.
Save harrisonmalone/bf5acdce12ac6ced98a76fcaa0a7a7ca to your computer and use it in GitHub Desktop.
terminal app built in js, menu logic provided 😻
// Create some kind javascript terminal app.
// I'm using a todo management system as an example. Feel free to implement your own todo system or create something else like a system for adding items to a restaurant menu or some kind of blogging system. For inspiration think back to what your colleagues presented in the ruby terminal apps.
// Make sure you break your functionality up into different functions; for this example i'm going to keep all of my code in the one file. You can use the following as your main app's loop, but will need to implement the functions themselves.
const readlineSync = require('readline-sync');
const todos = [];
const printMenu = () => {
console.log('1. Add new todo\n2. View todos\n3. Complete todo\n4. Quit');
}
const run = () => {
let option;
while (option !== "4") {
printMenu()
option = readlineSync.question('Which option would you like to choose? ');
switch(option) {
case "1":
// call add function
break;
case "2":
// call printAll function
break;
case "3":
// call complete function
break;
case "4":
console.log('I see you have already completed everything you need to today! Goodbye :)');
break;
default:
console.log('Please enter a valid option!');
}
}
}
run();
// Remember that you will need to initialize your project with npm to be able to install the readline-sync package. Look back at the npm docs on joli if you're unsure how to do this.
// You will notice there is a global todos array which is currently empty. Populate this array with objects in the following format { title: 'a title for the todo', isComplete: false }.
// Implement the following functions:
// add
// ask the user to type in a title for the todo
// create a todo object with the isComplete set to false
// insert new todo into the array of todos
// printAll
// iterate over the array of todos and print out a message to the console in the following format.
// [x] Learn Python
// [ ] Learn Javascript
// complete
// iterate over the todos and print them out to the console
// ask the user to select the todo to complete
// set the isComplete field of that todo to true
// Optional
// Implement moment JS to display how long ago a todo was created. Look into moment's fromNow() function to help with this logic.
// Implement an updateTodo function that allows the user to change the title of a todo
// Implement a printTodo function that prints one specific todo
// Implement a removeTodo function that removes a todo from the array
// Think about the repeated functionality of these three functions and move any repeated logic into its own function
// Move todo list logic into reusable module (separate file)
// Write todos to a file (CSV or JSON)
// Read todos from file when program starts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment