diff --git a/README.md b/README.md index a26c4c0..cc39282 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Build a guessing game in the command line! -Similar to the lesson, you will be building a guessing game! The main difference with this lab is the computer will generate a random number and it's up to you to guess it. +Similar to the lesson, you will be building a guessing game! The main difference with this lab is the computer will generate a random number and it's up to you to guess it.! ## Learning Objectives -- Practice building a command line game +- Practice building a command line game! - Understanding how to control the flow of a program - Practice writing code to make tests pass diff --git a/game.js b/game.js index 9305bf6..f41319a 100644 --- a/game.js +++ b/game.js @@ -1,51 +1,97 @@ -const rls = require('readline-sync') +const rls = require("readline-sync"); /** * Starts the game by prompting the user if they want to play * Calls either gameLoop() or quitGame() - * + * * @returns {undefined} */ const startGame = () => { + if(rls.keyInYN("Do you want to play? Y or N")) { + gameLoop() + } else { + quitGame() + } +} + +const gameLoop = () =>{ +console.log("Let's start!") +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 randNum = generateRandomNumber () +console.log(randNum) + + + +for(let guessCount = 10; guessCount > 0; guessCount -= 1) { + let inputGuess = rls.questionInt() + // console.log(inputGuess) + if (inputGuess === randNum) { + console.log("Congrats! You got it right!") + startGame() + } else if (inputGuess > randNum) { + console.log("Your guess is too high\n") + } else if (inputGuess < randNum) { + console.log("Your guess is too low\n"); + + } + } +//"Press return/enter to guess again \n" + + + + + + +} + +const quitGame = () => { + console.log("Have a nice life!") + console.log("Goodbye!") + process.exit() +} + + + /** * Logs "Goodbye!" * Calls process.exit() to quit the game - * + * * @returns {undefined} */ -const quitGame = () => { - -} +// const quitGame = () => { +// console.log("Goodbye!") +// process.exit +// }; /** * Controls the flow of the game. * Should prompt the user to play again once all * guesses have been made or correct answer guessed - * + * * @returns {undefined} */ -const gameLoop = () => { - -} - +// const gameLoop = () => {}; /*** - * Generates a random number + * Generates a random number * * @returns {number} - a number between 1 and 1000 */ const generateRandomNumber = () => { + return Math.floor(Math.random()*1000) +}; -} - -startGame() +startGame(); module.exports = { startGame, quitGame, gameLoop, - generateRandomNumber -} \ No newline at end of file + generateRandomNumber, +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..1ffa32e --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +const readlineSync = require("readline-sync") + +const name = readlineSync.question("What's your name? ") +console.log("Hi " + name + " nice to meet you!") + diff --git a/package.json b/package.json index d8fc643..7b48bcd 100644 --- a/package.json +++ b/package.json @@ -14,5 +14,14 @@ "jest": "^26.6.1", "mock-stdin": "^1.0.0", "readline-sync": "^1.4.10" - } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/rios-isabelle-farrah/Guessing-Game-cli-lab.git" + }, + "bugs": { + "url": "https://github.com/rios-isabelle-farrah/Guessing-Game-cli-lab/issues" + }, + "homepage": "https://github.com/rios-isabelle-farrah/Guessing-Game-cli-lab#readme", + "devDependencies": {} }