From dfb5e43946591d27f7905272780ec9126828151c Mon Sep 17 00:00:00 2001 From: Carlo Date: Sat, 5 Dec 2020 14:55:52 -0500 Subject: [PATCH 1/3] insert Hi --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9f80f03..9d5bfe2 100644 --- a/README.md +++ b/README.md @@ -93,3 +93,4 @@ $ node game.js 15 100 500 # 15 tries, 100 min, 500 max ## Resources - [how to parse command line arguments](https://nodejs.org/en/knowledge/command-line/how-to-parse-command-line-arguments/) +Hi From 39cfda5a7f6e659b6bfb07ff5b768b6eb34d673e Mon Sep 17 00:00:00 2001 From: Carlo Date: Sun, 20 Dec 2020 18:00:35 -0500 Subject: [PATCH 2/3] game --- package.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d8fc643..7b3f4d3 100644 --- a/package.json +++ b/package.json @@ -14,5 +14,13 @@ "jest": "^26.6.1", "mock-stdin": "^1.0.0", "readline-sync": "^1.4.10" - } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/carloecheverri/Guessing-Game-cli-lab.git" + }, + "bugs": { + "url": "https://github.com/carloecheverri/Guessing-Game-cli-lab/issues" + }, + "homepage": "https://github.com/carloecheverri/Guessing-Game-cli-lab#readme" } From 95d43c7c38b12559891c5cdc655ba41e9fe68d95 Mon Sep 17 00:00:00 2001 From: Carlo Date: Mon, 21 Dec 2020 00:14:12 -0500 Subject: [PATCH 3/3] game lab --- game.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/game.js b/game.js index 9305bf6..410046a 100644 --- a/game.js +++ b/game.js @@ -7,6 +7,15 @@ const rls = require('readline-sync') * @returns {undefined} */ const startGame = () => { + if(rls.keyInYN("Do you want to play a game?")) { + console.log("Let's start!") + gameLoop() + } + else { + console.log("Have a nice life!") + quitGame() + } + } @@ -17,6 +26,8 @@ const startGame = () => { * @returns {undefined} */ const quitGame = () => { + console.log("Goodbye!") + process.exit() } @@ -28,10 +39,42 @@ const quitGame = () => { * @returns {undefined} */ const gameLoop = () => { +console.log("I have a random number in mind") +console.log("It's between 1 and 1000") +console.log("You have 10 guesses total") +let randomNum = generateRandomNumber() +let guess; + + +for (let count = 10; count > 0; count--) { +let guess = rls.questionInt("what is your guess? \n") +if (guess === randomNum) { + console.log("Congrats! you got it right") + if (rls.keyInYN("Do you want to play again? \n")) { + gameLoop() + } + else { + quitGame() + } +} +else if( guess > randomNum) { + console.log("Your guess is too high") + } + else if(( guess < randomNum)) { + console.log ("Your guess is too low") + } + +} + console.log("You lose!") + quitGame() + + } + + /*** * Generates a random number * @@ -39,6 +82,10 @@ const gameLoop = () => { */ const generateRandomNumber = () => { + + + return Math.floor((Math.random() * 1000) + 1 ) + } startGame()