From 4684071b73d073a07873bed3819220efcea77591 Mon Sep 17 00:00:00 2001 From: Josh Parada Date: Fri, 5 Nov 2021 17:48:31 -0500 Subject: [PATCH 1/3] added index.js and tree.json --- .DS_Store | Bin 0 -> 6148 bytes package.json | 24 +++++++++++++ src/index.js | 72 +++++++++++++++++++++++++++++++++++++ src/tree.json | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 .DS_Store create mode 100644 package.json create mode 100644 src/index.js create mode 100644 src/tree.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d530e00780fa2567541fe67699dabc91ca4a12ad GIT binary patch literal 6148 zcmeHK!EVz)5S>j@x(*<6s6;Q7eBo9_X&Y7IfaHes&;t^}2o8W+JC0g|>y2WE2tts5 z1Ac<<;0yXW@OF1nl%^bu0PRS#Z#?^ESAMp4y+kB>lVpdeMMM&=vF4$<#&o~-6{~S( z4JgbQ5uMVI+Vqx+6}C(KjSA>zcZWt4(SY8e{q_75i0(J#n1c>9MjL_{7v zqeD8NK0N`p>70@)6$e);>Ub~4G+1Vdt?OCwv>5U1-{Vo17GLxl2+Hf1X`ZNQ zPfhZqFyn-_LrPD2$F0rTY%z*t$dtY2S|5G_*QR-u#mf=|W-A6)Z^fH%W61kD00xYeMPy*^N5IJ78mGV?Rp2L80(0O1 literal 0 HcmV?d00001 diff --git a/package.json b/package.json new file mode 100644 index 0000000..c9a1a5d --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "build-a-bot", + "version": "1.0.0", + "description": "Work with your team to build a bot (command line app)", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/xramirez/build-a-bot.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/xramirez/build-a-bot/issues" + }, + "homepage": "https://github.com/xramirez/build-a-bot#readme", + "keywords": [], + "dependencies": { + "fs": "^0.0.1-security", + "prompt-sync": "^4.2.0" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..a927627 --- /dev/null +++ b/src/index.js @@ -0,0 +1,72 @@ +const prompt = require('prompt-sync')({ sigint: true }); +const fs = require('fs'); + +//Be able to read from a file + +function playGame() { + let tree = fs.readFileSync('tree.json'); + let root = JSON.parse(tree); + //console.log(root); + + let node = root; + let input = ""; + let isGuess = false; + + while (isGuess == false) { + input = prompt(`${node.question} `).toLowerCase(); + if (input == 'yes') { + node = node.yes; + //console.log(node); + } + else if (input == 'no') { + node = node.no; + //console.log(node); + } + else + console.log("Make sure you answer with a yes or a no! Maybe doesn't cut it..."); + for (let options in node) { + if (options == 'guess') { + while (true) { + input = prompt(`${node.guess} `).toLowerCase(); + if (input == 'yes') + return true; + else if (input == 'no') + return false; + else + console.log("Make sure you answer with a yes or a no! Saying maybe doesn't cut it...") + } + } + } + } +} + +function startAndLoop() { + console.log("Welcome! This is the Pet Guessing Bot!\n\nGuess an animal that you'd usually have as a pet."); + console.log("We're going to ask you a list of questions to try and guess what kind of animal you're thinking of!") + console.log("You must either with answer with either yes or no!\n\nReady? Let's get down to it:"); + let repeatGame = true; + while (repeatGame == true) { + let gameWon = playGame(); + let input = "" + if (gameWon == true) + console.log("Yay! Thanks for playin'!"); + if (gameWon == false) + console.log("Looks like you've got a pet we didn't even think of!"); + input = prompt("Would you like to play again? ") + if (input == 'yes') { + console.log("Perfect! Let's do this:\n\n\n"); + } + else if (input == 'no') { + console.log("We're sad to see you go :( Thanks for playing!"); + repeatGame = false; + } + else + { + console.log("Well, you didn't say yes, so we'll call it for now. See you next time!"); + repeatGame = false; + } + } +} + +startAndLoop() +//console.log(root.question) \ No newline at end of file diff --git a/src/tree.json b/src/tree.json new file mode 100644 index 0000000..8d9ef2a --- /dev/null +++ b/src/tree.json @@ -0,0 +1,96 @@ +{ + "question": "Are you a mammal?", + "yes": { + "question": "Are you a rodent?", + "yes": { + "question": "Do you have a long tail?", + "yes": { + "question": "Is your tail furry?", + "yes": { + "guess": "Are you a ferret?" + }, + "no" : { + "guess": "Are you a mouse/rat?" + } + },"no" :{ + "question": "Do you have quills?", + "yes": { + "guess": "Are you a hedgehog?" + }, + "no" : { + "guess": "Are you a hamster/guinea pig?" + } + } + },"no": { + "question": "Do you have hooves?", + "yes": { + "question": "Are you usually used for milk?", + "yes": { + "question": "Are you used for beef patties?", + "yes": { + "guess": "Are you a cow?" + }, + "no": { + "guess": "Are you a goat?" + } + },"no": { + "question": "Are you used for bacon?", + "yes": { + "guess": "Are you a pig?" + },"no": { + "guess": "Are you a horse?" + } + } + },"no": { + "question": "Do you bounce?", + "yes": { + "guess": "Are you a rabbit?" + },"no": { + "question": "Do you have retractable claws?", + "yes": { + "guess": "Are you a cat?" + },"no": { + "guess": "Are you a dog?" + } + } + } + } + },"no": { + "question": "Are you a bird?", + "yes": { + "question": "Do you sing?", + "yes": { + "guess": "Are you a parrot?" + },"no": { + "question": "Do you gobble gobble?", + "yes": { + "guess": "Are you a turkey?" + },"no": { + "guess": "Are you a chicken?" + } + } + },"no": { + "question": "Are you a reptile?", + "yes": { + "question": "Do you have legs?", + "yes": { + "question": "Do you have a shell?", + "yes": { + "guess": "Are you a turtle?" + },"no": { + "guess": "Are you a lizard?" + } + },"no": { + "guess": "Are you a snake?" + } + },"no": { + "question": "Do you have legs?", + "yes": { + "guess": "Are you a frog?" + },"no": { + "guess": "Are you a fish?" + } + } + } + } +} \ No newline at end of file From a2138f5d216a7272b5e05bbaa04a6c81160d8b4e Mon Sep 17 00:00:00 2001 From: Josh Parada Date: Fri, 5 Nov 2021 17:50:58 -0500 Subject: [PATCH 2/3] removed files --- package.json | 24 ------------- src/index.js | 72 -------------------------------------- src/tree.json | 96 --------------------------------------------------- 3 files changed, 192 deletions(-) delete mode 100644 package.json delete mode 100644 src/index.js delete mode 100644 src/tree.json diff --git a/package.json b/package.json deleted file mode 100644 index c9a1a5d..0000000 --- a/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "build-a-bot", - "version": "1.0.0", - "description": "Work with your team to build a bot (command line app)", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/xramirez/build-a-bot.git" - }, - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/xramirez/build-a-bot/issues" - }, - "homepage": "https://github.com/xramirez/build-a-bot#readme", - "keywords": [], - "dependencies": { - "fs": "^0.0.1-security", - "prompt-sync": "^4.2.0" - } -} diff --git a/src/index.js b/src/index.js deleted file mode 100644 index a927627..0000000 --- a/src/index.js +++ /dev/null @@ -1,72 +0,0 @@ -const prompt = require('prompt-sync')({ sigint: true }); -const fs = require('fs'); - -//Be able to read from a file - -function playGame() { - let tree = fs.readFileSync('tree.json'); - let root = JSON.parse(tree); - //console.log(root); - - let node = root; - let input = ""; - let isGuess = false; - - while (isGuess == false) { - input = prompt(`${node.question} `).toLowerCase(); - if (input == 'yes') { - node = node.yes; - //console.log(node); - } - else if (input == 'no') { - node = node.no; - //console.log(node); - } - else - console.log("Make sure you answer with a yes or a no! Maybe doesn't cut it..."); - for (let options in node) { - if (options == 'guess') { - while (true) { - input = prompt(`${node.guess} `).toLowerCase(); - if (input == 'yes') - return true; - else if (input == 'no') - return false; - else - console.log("Make sure you answer with a yes or a no! Saying maybe doesn't cut it...") - } - } - } - } -} - -function startAndLoop() { - console.log("Welcome! This is the Pet Guessing Bot!\n\nGuess an animal that you'd usually have as a pet."); - console.log("We're going to ask you a list of questions to try and guess what kind of animal you're thinking of!") - console.log("You must either with answer with either yes or no!\n\nReady? Let's get down to it:"); - let repeatGame = true; - while (repeatGame == true) { - let gameWon = playGame(); - let input = "" - if (gameWon == true) - console.log("Yay! Thanks for playin'!"); - if (gameWon == false) - console.log("Looks like you've got a pet we didn't even think of!"); - input = prompt("Would you like to play again? ") - if (input == 'yes') { - console.log("Perfect! Let's do this:\n\n\n"); - } - else if (input == 'no') { - console.log("We're sad to see you go :( Thanks for playing!"); - repeatGame = false; - } - else - { - console.log("Well, you didn't say yes, so we'll call it for now. See you next time!"); - repeatGame = false; - } - } -} - -startAndLoop() -//console.log(root.question) \ No newline at end of file diff --git a/src/tree.json b/src/tree.json deleted file mode 100644 index 8d9ef2a..0000000 --- a/src/tree.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "question": "Are you a mammal?", - "yes": { - "question": "Are you a rodent?", - "yes": { - "question": "Do you have a long tail?", - "yes": { - "question": "Is your tail furry?", - "yes": { - "guess": "Are you a ferret?" - }, - "no" : { - "guess": "Are you a mouse/rat?" - } - },"no" :{ - "question": "Do you have quills?", - "yes": { - "guess": "Are you a hedgehog?" - }, - "no" : { - "guess": "Are you a hamster/guinea pig?" - } - } - },"no": { - "question": "Do you have hooves?", - "yes": { - "question": "Are you usually used for milk?", - "yes": { - "question": "Are you used for beef patties?", - "yes": { - "guess": "Are you a cow?" - }, - "no": { - "guess": "Are you a goat?" - } - },"no": { - "question": "Are you used for bacon?", - "yes": { - "guess": "Are you a pig?" - },"no": { - "guess": "Are you a horse?" - } - } - },"no": { - "question": "Do you bounce?", - "yes": { - "guess": "Are you a rabbit?" - },"no": { - "question": "Do you have retractable claws?", - "yes": { - "guess": "Are you a cat?" - },"no": { - "guess": "Are you a dog?" - } - } - } - } - },"no": { - "question": "Are you a bird?", - "yes": { - "question": "Do you sing?", - "yes": { - "guess": "Are you a parrot?" - },"no": { - "question": "Do you gobble gobble?", - "yes": { - "guess": "Are you a turkey?" - },"no": { - "guess": "Are you a chicken?" - } - } - },"no": { - "question": "Are you a reptile?", - "yes": { - "question": "Do you have legs?", - "yes": { - "question": "Do you have a shell?", - "yes": { - "guess": "Are you a turtle?" - },"no": { - "guess": "Are you a lizard?" - } - },"no": { - "guess": "Are you a snake?" - } - },"no": { - "question": "Do you have legs?", - "yes": { - "guess": "Are you a frog?" - },"no": { - "guess": "Are you a fish?" - } - } - } - } -} \ No newline at end of file From 2d48dd993d68b758c6e3148746a09bf53ada9b64 Mon Sep 17 00:00:00 2001 From: Josh Parada Date: Fri, 5 Nov 2021 17:51:55 -0500 Subject: [PATCH 3/3] added files --- .DS_Store | Bin 6148 -> 6148 bytes package.json | 24 +++++++++++++ src/index.js | 72 +++++++++++++++++++++++++++++++++++++ src/tree.json | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 package.json create mode 100644 src/index.js create mode 100644 src/tree.json diff --git a/.DS_Store b/.DS_Store index d530e00780fa2567541fe67699dabc91ca4a12ad..68586da00124b12933dffab2131c028d80d8be1e 100644 GIT binary patch delta 92 zcmZoMXfc=|#>CJzu~2NHo}wrt0|NsP3otPFGPpA6G2}9&c;-wjRA*$I?80Qac^Y#e r%jN~lSD7}mbMSKjwQZir{GE9+zlbg;Naq0{W|(ZlBfU9BWC=3>$AA?w delta 434 zcmZoMXfc=|#>B)qu~2NHo}wr#0|Nsi1A_nqLn1>uLn?zFLl#5v#)HclEkQCo3;0ltoqsWJ6UY zl@}L44Lg}skds+lVqkEck%^gwm5rT)gNuWUmn$|nBfmVjB(bEl*eS6n8pI1oEXhcM zvP1IobKva6q_FzT)be-%5$F88lElos)FQC%%#>81nwap+yp;TMr~J~qlwz