-
Notifications
You must be signed in to change notification settings - Fork 0
todoCLI homework - week 3 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
35f0171
bbb674c
96b12b8
78c892e
dca1e37
7f9964c
c1b4612
622341a
1a19f09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 0 [ ] Take out the trash | ||
| 1 [ ] Buy grocery | ||
| 2 [ ] Play basketball |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| const readline = require('readline'); | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
| let myStuff = []; | ||
| //The above "myStuff" array will be storing the todo's that a user enters. | ||
| function userInput(answer){ | ||
| if (answer === 'v'){ | ||
| viewList(); | ||
| } else if (answer === 'n'){ | ||
| addNewItem(); | ||
| } else if (answer[0] === 'c') { | ||
| completeItem(answer); | ||
| } else if (answer[0] === 'd') { | ||
| deleteItem(answer); | ||
| } else if (answer === 'q'){ | ||
| quitList(); | ||
| } else { | ||
| console.log(`You must enter one of the following: v, n, cX (where X is a number), dX (where X is a number), q`); | ||
| menu(); | ||
| }; | ||
| }; | ||
|
|
||
| function menu () {rl.question( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function menu () {rl.question(should be on separate lines function menu() {
rl.question(There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job naming this function so that it could be reused |
||
| `Welcome to ToDo CLI!\n--------------------\n(v) View ∙ (n) New ∙ (cX) Complete ∙ (dX) Delete ∙ (q) Quit\n>`, | ||
| userInput)}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should put the |
||
| menu(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should not be indented if you are calling this now. Otherwise it gives the impression that this should be/currently is within another function |
||
|
|
||
| function viewList (){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When naming functions, please follow the following convention: function functionName() {
// ...
} |
||
| console.log(`You're viewing your to-do list`); | ||
| if (myStuff.length === 0) { | ||
| console.log('but your to-do list is empty') | ||
| } else { | ||
| for (let i = 0; i < myStuff.length; i++){ | ||
| if (myStuff[i][0] === false) { | ||
| console.log (`${i} [ ] ${myStuff[i][1]}`) | ||
| } else if (myStuff[i][0] === true) { | ||
| console.log(`${i} [✓] ${myStuff[i][1]}`) | ||
| } | ||
| } | ||
| }; | ||
| menu(); | ||
| }; | ||
|
|
||
| function addNewItem (){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| console.log(`you're adding a new to-do item`); | ||
| rl.question(`What task would you like to add?\n`, answer =>{ | ||
| myStuff.push([false, answer]); | ||
| menu(); | ||
| }); | ||
| }; | ||
|
|
||
| function completeItem (answer) { | ||
| let userInputNumber = ''; | ||
| for (let i = 1; i<answer.length; i++){ | ||
| userInputNumber += answer[i] | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This for loop essentially slices off the first character within the answer string. const userInputNumber = answer.slice(1); |
||
|
|
||
| myStuff[userInputNumber][0] = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should check that |
||
| console.log(`Completed "${myStuff[userInputNumber][1]}"`) | ||
| menu(); | ||
| }; | ||
|
|
||
| function deleteItem (answer) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| let userInputNumber = ''; | ||
| for (let i = 1; i<answer.length; i++){ | ||
| userInputNumber += answer[i] | ||
| }; | ||
|
|
||
| let itemToDelete = myStuff.splice(userInputNumber,1) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as #3 (comment) |
||
| console.log(`Deleted "${itemToDelete[0][1]}"`); | ||
| menu(); | ||
| }; | ||
|
|
||
| function quitList (){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| console.log(`See you soon! 😄`); | ||
| rl.close(); | ||
| }; | ||
|
|
||
| //Nov 23, 2018 | ||
| //The above is just to create a general/barebone structure | ||
| //of the code. This is just to build something, so that | ||
| //I can see the "main page" of todoCLI.js asking a user to | ||
| //choose from the v, n, cX, dX and q options. | ||
|
|
||
| /** | ||
| * MY PROPOSED ALGORITHM - Nov 23, 2018 | ||
| * step 1 - create a general/barebone structure to show the | ||
| * interface as soon as todoCLI.js is run in the terminal. | ||
| * step 2 - In the callback function of rl.question(), call | ||
| * another function called "userInput". | ||
| * step 3 - In this "userInput" function, there will be various "if...else" statements | ||
| * responsible for the available choices. | ||
| * I expect to use the following methods for each option: | ||
| * view --> fs.readFile, rl.close() | ||
| * new --> fs.writeFile, rl.close() | ||
| * complete->fs.writeFile, rl.close() | ||
| * delete--> fs.unlink, rl.close() | ||
| * quit --> rl.close() | ||
| */ | ||
|
|
||
| /** Nov 25, 2018 | ||
| * I realized I started coding for the "stretch" homework. | ||
| * So, I decided to rewrite my code for the "non-stretch" homework first. | ||
| * I will tackle the "stretch" homework later. | ||
| * | ||
| * | ||
| * | ||
| ** Nov 30, 2018 | ||
| * I cleaned up my code by deleting unneccesary comments and empty spaces. | ||
| * I cleaned up my code by indenting properly. | ||
| * I cleaned up my code by naming my variable with meaningful word choices. | ||
| */ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job naming this function so that it could be reused