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 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() 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" }