Coder Social home page Coder Social logo

build-a-number-guessing-game-project-freecodecamp's Introduction

1. Prepare database

psql --username=freecodecamp --dbname=postgres
CREATE DATABASE number_guess;
\c number_guess

CREATE TABLE users(
	user_id SERIAL NOT NULL, 
	username VARCHAR(22) UNIQUE NOT NULL,
	frequent_games INTEGER DEFAULT 0 NOT NULL
);

CREATE TABLE games(
 	game_id    SERIAL NOT NULL, 
 	user_id    INTEGER NOT NULL, 
 	best_guess INTEGER DEFAULT 0 NOT NULL
);

2. Primary Key and Foreign Key assignment

ALTER TABLE users ADD PRIMARY KEY (user_id)
ALTER TABLE games ADD PRIMARY KEY (game_id)
ALTER TABLE games ADD FOREIGN KEY (user_id) REFERENCES users (user_id)

3. Compact sql db schema into number_guess.sql

quit
pg_dump -cC --inserts -U freecodecamp number_guess > number_guess.sql

4. Prepare git directory

mkdir number_guesssing_game

cd number_guesssing_game

git init

git checkout -b main

5. Prepare shell script file

touch number_guess.sh

git add number_guess.sh

git commit -m "Initial commit"

chmod +x number_guess.sh

git add number_guess.sh

git commit -m "refactor: give executable permissions on number_guess.sh"

6. Copy scipt line by line, meanwhile commit changes on terminal

  1. Create function input name & input number guess
  • At number_guess.sh file : Copy function INPUT_NAME() & INPUT_GUESS()
  • At terminal, type:

git add number_guess.sh

git commit -m "feat: create function to input name and input number guess"

  1. Create function to check input guess number
  • At number_guess.sh file : Copy function CHECK_ANSWER()
  • At terminal, type :

git add number_guess.sh

git commit -m "feat: create function to check the guess number"

  1. Create function to save the user
  • At number_guess.sh file : Copy function SAVE_USER()
  • At terminal, type :

git add number_guess.sh

git commit -m "feat: create function to save new user"

4 .Create function to save the game

  • At number_guess.sh file : copy function SAVE_GAME()
  • At terminal, type:

git add number_guess.sh

git commit -m "feat: create function to save the game"

Last step: Run The Script and enjoy the result!

See the full solution here: Bash script file and PostgreSQL file

My result:

Finish project

Finished all projects!

Finished all projects

build-a-number-guessing-game-project-freecodecamp's People

Contributors

quanganh2001 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.