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
53 changes: 35 additions & 18 deletions game.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
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 = () => {


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

const quitGame = () => {
console.log("Have a nice life!")
console.log("Goodbye!")
process.exit()
}

const startGame = () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you reordered your functions instead of just changing to ES5 in order to call them later in your startGame function

if(rls.keyInYN("Do you want to play? Y or N")) {
gameLoop()
} else {
quitGame()
}
}

/**
* 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": {}
}