Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
80 changes: 63 additions & 17 deletions game.js
Original file line number Diff line number Diff line change
@@ -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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get in the habit of leaving your console.logs in when you push to github




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
}
generateRandomNumber,
};
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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!")

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}