{ "id": "freeCodeCamp/learn-bash-and-sql-by-building-a-bike-rental-shop:v1.0.0", "version": "2.0.0", "summary": { "title": "Learn Bash and SQL by Building a Bike Rental Shop", "description": "> Welcome to the Bash and SQL lessons!" }, "config": { "setup": { "commands": [ "./.freeCodeCamp/setup.sh", "cd .freeCodeCamp && npm install" ], "commits": [ "4b08d6515a54c1fb28be33d1eeae8d2f3e7361cc" ] }, "testRunner": { "command": "npm run programmatic-test", "args": { "tap": "--reporter=mocha-tap-reporter" }, "directory": ".freeCodeCamp" }, "repo": { "uri": "https://github.com/freeCodeCamp/learn-bash-and-sql-by-building-a-bike-rental-shop", "branch": "v2.0.0" }, "continue": { "commands": [ "./.freeCodeCamp/setup.sh", "./.freeCodeCamp/reset.sh" ] }, "reset": { "commands": [ "./.freeCodeCamp/setup.sh", "./.freeCodeCamp/reset.sh" ] }, "dependencies": [ { "name": "node", "version": ">=10" } ], "webhook": { "url": "https://api.freecodecamp.org/coderoad-challenge-completed", "events": { "init": false, "reset": false, "step_complete": false, "level_complete": false, "tutorial_complete": true } } }, "levels": [ { "id": "10", "title": "Start the Terminal", "summary": "", "content": "", "steps": [ { "id": "10.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d62d31edaf6d69565f67e9ed7943aa46b28482c7" ] }, "content": "**The first thing you need to do is start the terminal.** Do that by clicking the \"hamburger\" menu at the top left of the screen, going to the \"terminal\" section, and clicking \"new terminal\". Once you open a new one, type `echo hello terminal` into the terminal and press enter.", "hints": [ "Capitalization matters", "If the tests don't run automatically, try typing `exit` into the terminal and redoing the instructions" ] } ] }, { "id": "20", "title": "Log in to Psql", "summary": "", "content": "", "steps": [ { "id": "20.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "9830cd06d0e462b8b578a4969cd75af6666fac38" ] }, "content": "You are going to build a bike rental shop. It will have a database, and a bash script to interact with the database. Use the terminal to connect to PostgreSQL by entering `psql --username=freecodecamp --dbname=postgres`.", "hints": [ "Type the above command into the terminal and press enter", "Type `psql --username=freecodecamp --dbname=postgres` into the terminal and press enter" ] } ] }, { "id": "30", "title": "List Databases", "summary": "", "content": "", "steps": [ { "id": "30.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "5bdf02abc59ffe99638af1664c91e6a98ce38c51" ] }, "content": "List the databases with `\\l` to see what databases are here.", "hints": [ "Type `\\l` into the psql prompt and press enter", "Type `psql --username=freecodecamp --dbname=postgres` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "40", "title": "Create Database `bikes`", "summary": "", "content": "", "steps": [ { "id": "40.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b3c920a800bf4b62480581f2065e9ad8ea5222b0" ] }, "content": "You need your own database for the bike shop. Create a new database named `bikes`.", "hints": [ "Use the `CREATE DATABASE` keywords", "Here's an example: `CREATE DATABASE database_name;`", "Type `CREATE DATABASE bikes;` into the psql prompt and press enter", "Type `psql --username=freecodecamp --dbname=postgres` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "50", "title": "List Databases", "summary": "", "content": "", "steps": [ { "id": "50.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "0d557f4fb1477da6eec9610649b3f519df1a7ebb" ] }, "content": "List databases again to make sure your database got created.", "hints": [ "Use the **l**ist shortcut command", "Type `\\l` into the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "60", "title": "Connect to `bikes`", "summary": "", "content": "", "steps": [ { "id": "60.1", "setup": { "watchers": [ "../pg.log" ], "commits": [ "804cadc3ab6866b3bbb11a79d6fef6e5f6ca4cb9" ] }, "content": "There it is. **C**onnect to it so you can start building the structure of your bike shop database.", "hints": [ "Use the **c**onnect shortcut command", "Add the database name to the command", "It's the `\\c` command", "Here's an example: `\\c database_name`", "Try entering `\\c bikes` into the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "70", "title": "Create table `bikes`", "summary": "", "content": "", "steps": [ { "id": "70.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "806519191c296cbe9b950d417b5f29124b7465df" ] }, "content": "Your database needs three tables. One for your bike inventory, one for your customers, and one for the bikes that are rented out. Create a table named `bikes` in your database for the inventory.", "hints": [ "Use the `CREATE TABLE` keywords", "Don't forget the parenthesis", "Here's an example: `CREATE TABLE table_name();`", "Try entering `CREATE TABLE bikes();` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "80", "title": "Display the tables", "summary": "", "content": "", "steps": [ { "id": "80.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "4c675e83042a9b1211649d2160a4027b9072a5c8" ] }, "content": "**D**isplay the tables to make sure your table got created.", "hints": [ "Use the **d**isplay shortcut command", "It's the `\\d` command", "Type `\\d` into the psql prompt and press enter", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "90", "title": "Add column `bike_id`", "summary": "", "content": "", "steps": [ { "id": "90.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "80e6f0226a42759f7101aa95c8a241be433507fa" ] }, "content": "The table will have a few columns for bike information. First, is a unique ID column. Add a column to the `bikes` table named `bike_id`. Give it a type of `SERIAL` and make it a `PRIMARY KEY`.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL`, and `PRIMARY KEY` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE bikes ADD COLUMN bike_id SERIAL PRIMARY KEY;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "100", "title": "Display `bikes` Details", "summary": "", "content": "", "steps": [ { "id": "100.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "1766f2604ae15802da3f6569267bdd0379e36ac7" ] }, "content": "Use the **d**isplay command to view the details of the `bikes` table.", "hints": [ "It's the `\\d` command", "Add the table name to the command", "Try entering `\\d bikes` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "110", "title": "Add `type` column", "summary": "", "content": "", "steps": [ { "id": "110.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "7782e36acb0f1ece4079eeb3bde1a9626ef3d9cb" ] }, "content": "The first column is set. Add a column named `type` for the type of bike. Make it a `VARCHAR(50)` and give it a constraint of `NOT NULL`.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR(50)`, and `PRIMARY KEY` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE bikes ADD COLUMN type VARCHAR(50) NOT NULL;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "120", "title": "Display `bikes` details", "summary": "", "content": "", "steps": [ { "id": "120.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b5013ab84369cd7644471ffe85d66c1c5e13fc6a" ] }, "content": "Display the details of the `bikes` table again.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d bikes` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in" ] } ] }, { "id": "130", "title": "Add Column `size`", "summary": "", "content": "", "steps": [ { "id": "130.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "409564d068666998413a6636eccdaa02114e3197" ] }, "content": "The first two columns look good. Add a column named `size` to the `bikes` table that is an `INT` and has the `NOT NULL` constraint. This will be for the size of each bike.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `INT`, and `NOT NULL` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE bikes ADD COLUMN size INT NOT NULL;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in" ] } ] }, { "id": "140", "title": "Add Column `available`", "summary": "", "content": "", "steps": [ { "id": "140.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "cf7f8fb3b6e6f8877be2b7e7b5ce14f2047af21f" ] }, "content": "Add another column to the table named `available`. Make it a `boolean` and has a constraint of `NOT NULL`. Also give it a default value of `TRUE`. This will be set to `false` when someone rents out a bike.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `BOOLEAN`, `NOT NULL` and `DEFAULT TRUE` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS DEFAULT;`", "Try entering `ALTER TABLE bikes ADD COLUMN available BOOLEAN NOT NULL DEFAULT TRUE;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in" ] } ] }, { "id": "150", "title": "Display `bikes` details", "summary": "", "content": "", "steps": [ { "id": "150.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "6fcd9fb666adf2ac11efd2c77d6ba1440c089419" ] }, "content": "Display the details of the `bikes` table again so you can make sure it's how you want it.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d bikes` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "160", "title": "Create Table `customers`", "summary": "", "content": "", "steps": [ { "id": "160.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "c3193f4e8ea22785f9af35fb2ec5e607b9c6b121" ] }, "content": "That table is done for now. Create another table named `customers`. It will store a name and phone number for each customer that rents a bike.", "hints": [ "Use the `CREATE TABLE` keywords", "Don't forget the parenthesis", "Here's an example: `CREATE TABLE table_name();`", "Try entering `CREATE TABLE customers();` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "170", "title": "Add Column `customer_id`", "summary": "", "content": "", "steps": [ { "id": "170.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "a9f3f9439953c32ddd4e89c98719640b634515ab" ] }, "content": "Add a `customer_id` column to your new table that is a type of `SERIAL` and make it a `PRIMARY KEY`.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL`, and `PRIMARY KEY` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE customers ADD COLUMN customer_id SERIAL PRIMARY KEY;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "180", "title": "Display `customers` Details", "summary": "", "content": "", "steps": [ { "id": "180.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "a41e139cd6232efb8c4209e4e176864dbf62a682" ] }, "content": "Display the details of the `customers` table so you can make sure your new column is there.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d customers` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "190", "title": "Add Column `phone`", "summary": "", "content": "", "steps": [ { "id": "190.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "5167886358297b88912088f1b6ff725b0b624db0" ] }, "content": "There it is. Add a column named `phone` for customers phone numbers. Make it a varying character that has a maximum length of `15` characters. Also make sure it can't be null, and that it has to be unique.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()`, `NOT NULL`, and `UNIQUE` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE customers ADD COLUMN phone VARCHAR(15) NOT NULL UNIQUE;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "200", "title": "Add Column `name`", "summary": "", "content": "", "steps": [ { "id": "200.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "1f1c7f671f80d4ce89cef407128c8a1a354ba9aa" ] }, "content": "Add the last column. Call it `name` and make it a `VARCHAR(40)` that can't be null.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `VARCHAR()`, and `NOT NULL` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE customers ADD COLUMN name VARCHAR(40) NOT NULL;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "210", "title": "Display `customers` Details", "summary": "", "content": "", "steps": [ { "id": "210.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "eb572362a32d8a5dc7b8dbaf38de7d1b046fb2b4" ] }, "content": "Display the details of the `customers` table.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d customers` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "220", "title": "Create Table `rentals`", "summary": "", "content": "", "steps": [ { "id": "220.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "1d57bf3a5bb7597d0e81f5c68152ed0cfdd6f447" ] }, "content": "That table is finished. Lastly, you need a table to store which bikes are rented and who has rented them. Create a new table named `rentals`.", "hints": [ "Use the `CREATE TABLE` keywords", "Don't forget the parenthesis", "Here's an example: `CREATE TABLE table_name();`", "Try entering `CREATE TABLE rentals();` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "230", "title": "Add Column `rental_id`", "summary": "", "content": "", "steps": [ { "id": "230.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "56d91299d51e399cf3e764cef7c3ebd91e290e57" ] }, "content": "Add a `rental_id` column to your new table. Make it automatically increment with `SERIAL` and make it the primary key for this table.", "hints": [ "The other two properties are `SERIAL` and `PRIMARY KEY`", "Use the `ALTER TABLE`, `ADD COLUMN`, `SERIAL`, and `PRIMARY KEY` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE rentals ADD COLUMN rental_id SERIAL PRIMARY KEY;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "240", "title": "Display `rentals` Details", "summary": "", "content": "", "steps": [ { "id": "240.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "4b254af70c8974cdb630729117162ada2f3b7dd8" ] }, "content": "Display the details of the `rentals` table.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d rentals` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "250", "title": "Add Column `customer_id`", "summary": "", "content": "", "steps": [ { "id": "250.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "1bf3a00dec97f1219a18cce088fdd42a6a62b9e2" ] }, "content": "Next, you need a column for the customer who is renting a bike. Add column named `customer_id`. This will have an id of a customer from the customers table. Make the column an `INT` and `NOT NULL` to start.", "hints": [ "Add the column to the `rentals` table", "Use the `ALTER TABLE`, `ADD COLUMN`, `INT`, and `NOT NULL` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE rentals ADD COLUMN customer_id INT NOT NULL;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "260", "title": "Set `customer_id` Foreign Key", "summary": "", "content": "", "steps": [ { "id": "260.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b84640be2b65aa2af8589acb21c58863991f47f9" ] }, "content": "Make the column you just added a foreign key that references the `customer_id` column from the `customers` table. Here's an example of how you can do that:\n\n```sql\nALTER TABLE table_name ADD FOREIGN KEY(column_name) REFERENCES referenced_table(referenced_column);\n```", "hints": [ "Without the keywords, it looks like tihs: `rentals customer_id customers(customer_id)`", "Try entering `ALTER TABLE rentals ADD FOREIGN KEY(customer_id) REFERENCES customers(customer_id);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "270", "title": "Display `rentals` Details", "summary": "", "content": "", "steps": [ { "id": "270.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "6cafe6900af9dde93435262b02ba59791560b8c1" ] }, "content": "Display the details of the `rentals` table to make sure your key is set.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d rentals` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "280", "title": "Add Column `bike_id`", "summary": "", "content": "", "steps": [ { "id": "280.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "813351fe30a62648e3ece0439a7d63306d7bf957" ] }, "content": "That foreign key is set. You need another column so you know what bike a customer is renting. Add a column named `bike_id` and make it an `INT` and `NOT NULL`.", "hints": [ "Add the column to the `rentals` table", "Use the `ALTER TABLE`, `ADD COLUMN`, `INT`, and `NOT NULL` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE rentals ADD COLUMN bike_id INT NOT NULL;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "290", "title": "Add `bike_id` Foreign Key", "summary": "", "content": "", "steps": [ { "id": "290.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "3249fb6a154ffbf43e089c5547296476ee53e95e" ] }, "content": "Make that column a foreign key that references the `bike_id` column from the `bikes` table so you know what bike the id is for.", "hints": [ "Here's the example again: `ALTER TABLE table_name ADD FOREIGN KEY(column_name) REFERENCES referenced_table(referenced_column);`", "Without the keywords, it looks like tihs: `rentals bike_id bikes(bike_id)`", "Try entering `ALTER TABLE rentals ADD FOREIGN KEY(bike_id) REFERENCES bikes(bike_id);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "300", "title": "Display `rentals` Details", "summary": "", "content": "", "steps": [ { "id": "300.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "2a57acab8380041b732496c7bbaad34c9c118c08" ] }, "content": "Display the details of the `rentals` table so you can make sure the key is correct.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d rentals` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "310", "title": "Add `date_rented` Column", "summary": "", "content": "", "steps": [ { "id": "310.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "edec8d112d980c04be6b1f54f4ac5d002436da01" ] }, "content": "Moving along. You want to know when a customer rents a bike, and when it gets returned. Add a column to your `rentals` table named `date_rented` that's a type of `DATE`. Make sure the entry can't be null, and give it a default value of `NOW()`.", "hints": [ "Add the column to the `rentals` table", "Use the `ALTER TABLE`, `ADD COLUMN`, `DATE`, `NOT NULL`, and `DEFAULT NOW()` keywords", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE CONSTRAINTS;`", "Try entering `ALTER TABLE rentals ADD COLUMN date_rented DATE NOT NULL DEFAULT NOW();` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "320", "title": "Display `rentals` Details", "summary": "", "content": "", "steps": [ { "id": "320.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b4d7eb147bf8049c260de24c26f2c61d14014fb0" ] }, "content": "Display the details of the `rentals` table again.", "hints": [ "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d rentals` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "330", "title": "Add Column `date_returned`", "summary": "", "content": "", "steps": [ { "id": "330.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "7ae551f37dd4e617b13e11627ac2cdc563adc27b" ] }, "content": "It looks good. Lastly, you need a column for when a customer returns a bike. Add a column named `date_returned` that's a type of `DATE`.", "hints": [ "Use the `ALTER TABLE`, `ADD COLUMN`, `DATE` keywords", "Add the column to the `rentals` table", "Here's an example: `ALTER TABLE table_name ADD COLUMN column_name TYPE;`", "Try entering `ALTER TABLE rentals ADD COLUMN date_returned DATE;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "340", "title": "Display `rentals` Details", "summary": "", "content": "", "steps": [ { "id": "340.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "bb637a0426cb8fba1608ac0743d826466667b261" ] }, "content": "View the details of the table again.", "hints": [ "It's the `rentals` table", "Use the **d**isplay shortcut command", "Add the table name to the command", "Here's an example: `\\d table_name`", "Try entering `\\d rentals` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "350", "title": "Display Tables", "summary": "", "content": "", "steps": [ { "id": "350.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "c154aac0808429ac37a2eddec46c5be92b9b39cb" ] }, "content": "The tables are all finished. Display all the tables so you can see what you ended up with.", "hints": [ "Use the **d**isplay shortcut command", "It's the `\\d` command", "Enter `\\d` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "360", "title": "Insert 27 inch Mountain Bike", "summary": "", "content": "", "steps": [ { "id": "360.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "aece2f81cc21923bd5995f0461326615fda3ac65" ] }, "content": "You have nine bikes in your inventory. Add the first one to your `bikes` table. It has a `type` of `Mountain` and a `size` of `27`. Make sure to put your `VARCHAR` values in single quotes. The `bike_id` and `available` columns should be filled in automatically, so you don't need to worry about those.", "hints": [ "Use the `INSERT INTO` and `VALUES` keywords", "Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value);`", "View the details of the `bikes` table with `\\d bikes` to see what values it expects", "Try entering `INSERT INTO bikes(type, size) VALUES('Mountain', 27);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "370", "title": "Select all from Bikes", "summary": "", "content": "", "steps": [ { "id": "370.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "33a6dedc8fbf44c2a542279cabb1d43e9c3d9c2b" ] }, "content": "View all the columns in your bikes table with `SELECT`.", "hints": [ "Use `*` to view all the columns", "Here's an example: `SELECT * FROM table_name;`", "Try entering `SELECT * from bikes;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "380", "title": "Insert 28 inch Mountain Bike", "summary": "", "content": "", "steps": [ { "id": "380.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b5e5249cdde9c77aa9e0aa11b8e6a52e82a8f707" ] }, "content": "Looks like it's all working, the `bike_id` and `available` columns were filled in automatically. Insert another bike. Give it a `type` of `Mountain` and a `size` of `28`.", "hints": [ "Make sure to put your `VARCHAR` values in single quotes", "Use the `INSERT INTO` and `VALUES` keywords", "Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value);`", "Try entering `INSERT INTO bikes(type, size) VALUES('Mountain', 28);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "390", "title": "Insert 29 inch Mountain Bike", "summary": "", "content": "", "steps": [ { "id": "390.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "98fb82045d64caacac14ec3d0834522b30460cf8" ] }, "content": "Add another `Mountain` bike to your inventory. Make it a `29` inch bike.", "hints": [ "Use the `INSERT INTO` and `VALUES` keywords", "Make sure to put your `VARCHAR` values in single quotes", "Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value);`", "Try entering `INSERT INTO bikes(type, size) VALUES('Mountain', 29);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "400", "title": "Insert 27 inch Road Bike", "summary": "", "content": "", "steps": [ { "id": "400.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b59342185f717be9def4bfb92053948b233c6be4" ] }, "content": "Add a `27` inch `Road` bike to the table.", "hints": [ "Use the `INSERT INTO` and `VALUES` keywords", "Make sure to put your `VARCHAR` values in single quotes", "Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value);`", "Try entering `INSERT INTO bikes(type, size) VALUES('Road', 27);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "410", "title": "Select all from Bikes", "summary": "", "content": "", "steps": [ { "id": "410.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "c98e77f1e35f6e12f45a3d6b42a13d2cd4aca0a8" ] }, "content": "Use `SELECT` to view all the data in the `bikes` table again.", "hints": [ "Use `*` to view all the columns", "Here's an example: `SELECT * FROM table_name;`", "Try entering `SELECT * from bikes;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "420", "title": "Insert 28 and 29 inch Road Bikes", "summary": "", "content": "", "steps": [ { "id": "420.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "2560053ee745fe05544c834a3ed32c7be0a424fa" ] }, "content": "Add the two bikes to your inventory, they are `28` and `29` inch `Road` bikes. Try to add them both with one command.", "hints": [ "Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value), (value, value);`", "Make sure to put your `VARCHAR` values in single quotes", "Try entering `INSERT INTO bikes(type, size) VALUES('Road', 28), ('Road', 29);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "430", "title": "Insert 19, 20, 21 inch BMX Bikes", "summary": "", "content": "", "steps": [ { "id": "430.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "362846425ceb4c6fa0c0d4d65697b7d47ba89d5c" ] }, "content": "There's three more bikes. Add `19`, `20`, and `21` inch `BMX` bikes to your table. Try to add them with one command.", "hints": [ "Here's an example: `INSERT INTO table_name(column_name, column_name) VALUES(value, value), (value, value), (value, value);`", "Make sure to put your `VARCHAR` values in single quotes", "Try entering `INSERT INTO bikes(type, size) VALUES('BMX', 19), ('BMX', 20), ('BMX', 21);` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "440", "title": "Select all from Bikes", "summary": "", "content": "", "steps": [ { "id": "440.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "66102c8f50503bc7963b404e8001dae82080ffbe" ] }, "content": "View all the data in your bikes table.", "hints": [ "Use `SELECT` with `*` to view all the columns", "Here's an example: `SELECT * FROM table_name;`", "Try entering `SELECT * from bikes;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in first" ] } ] }, { "id": "450", "title": "touch bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "450.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "b5a3c99dc8b754830f154377b80eba6307f7bef3" ] }, "content": "Your current inventory is all added. For the rest of the project, I recommend leaving that terminal open and connected, and that you should \"split\" the terminal so you have a second one to use for bash commands. Do that by clicking the \"hamburger\" menu at the top left of the window, going to the \"terminal\" section, and clicking \"split terminal\". After you have opened it, use the `touch` command to create a file named `bike-shop.sh` in the `project` folder.", "hints": [ "Try entering `touch bike-shop.sh` in the terminal", "Make sure it's the regular terminal, and not the psql one", "Make sure you are in the `project` folder first", "If you opened a new terminal instead of splitting it, you can close it by entering `exit` and try again", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you want" ] } ] }, { "id": "460", "title": "Add shebang!", "summary": "", "content": "", "steps": [ { "id": "460.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "bfb18a92495aad8d168d825934cc16ed71704ff3" ] }, "content": "This file will be the program for your bike rental shop. Open the file and add a \"shebang\" at the top so it uses `bash` when it's executed. If you don't remember, it looks like this: `#!/bin/bash`.", "hints": [ "Add `#!/bin/bash` to the top of your `bike-shop.sh` file" ] } ] }, { "id": "470", "title": "Add echo Bike Rental Shop", "summary": "", "content": "", "steps": [ { "id": "470.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "191991e3d204c60165e16a78a73dc906b4e0727b" ] }, "content": "In the file, use `echo` with the `-e` flag to print `~~~~~ Bike Rental Shop ~~~~~` with a new line at the beginning and end.", "hints": [ "The newline character is `\\n`", "Use double quotes around the message so the new lines are printed", "Here's an example: `echo -e \"\\n\\n\"`", "Add `echo -e \"\\n~~~~~ Bike Rental Shop ~~~~~\\n\"` to the `bike-shop-sh` file" ] } ] }, { "id": "480", "title": "chmod +x bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "480.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "a39dcb0d99f16bb86eaf6d94bf2a20abac109793" ] }, "content": "Use the terminal (not the psql one) and the `chmod` command to make your file executable. Add the `+x` flag and `bike-shop.sh` to the command to do that.", "hints": [ "Here's an example: `chmod +x `", "Try entering `chmod +x bike-shop.sh` in the terminal", "Make sure you are in the `project` folder first" ] } ] }, { "id": "490", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "490.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "18776b7817b049fc22dc945211e61286ac711504" ] }, "content": "Type `./bike-shop.sh` in the terminal to run your script.", "hints": [ "Make sure to use the regular terminal and not the psql one", "Make sure you are in the `project` folder first" ] } ] }, { "id": "510", "title": "Add MAIN_MENU", "summary": "", "content": "", "steps": [ { "id": "510.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "72bb639e4b418bfd003248efceecf5b961e3bf11" ] }, "content": ":smile: In the script, create an empty function named `MAIN_MENU`. This will have a few options to enter when the script runs to rent or return a bike.", "hints": [ "Here's an example:\n```sh\nFUNCTION_NAME() {\n\n}\n```", "Add this to the bottom of the script:\n```sh\nMAIN_MENU() {\n\n}\n```" ] } ] }, { "id": "520", "title": "Add echo How may I help you?", "summary": "", "content": "", "steps": [ { "id": "520.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "ecc9d3e9d7230acb09ac9cfbcf14f2525fc27f92" ] }, "content": "In your function, echo the text `How may I help you?` so that there's a greeting when you go to the menu.", "hints": [ "Add `echo \"How may I help you?\"` in the designated area" ] } ] }, { "id": "530", "title": "Add MAIN_MENU function call", "summary": "", "content": "", "steps": [ { "id": "530.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "68d523b289904946b0b9cf345a96ebe9f045089c" ] }, "content": "Call your `MAIN_MENU` at the bottom of the file so the function runs when you start the script.", "hints": [ "Add `MAIN_MENU` at the bottom of the file" ] } ] }, { "id": "540", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "540.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "b86bd9066678fcb64a9b255344f720bfbea8c14d" ] }, "content": "Run the file in the terminal again so you can see what it is outputting.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "630", "title": "Add MAIN_MENU Options", "summary": "", "content": "", "steps": [ { "id": "630.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "33c51097dc4d1a846eb770d30088b378e86d5202" ] }, "content": "It's coming along. Add another `echo` command **in the function** below the other one. Make it output text that looks like this:\n\n```sh\n\n1. Rent a bike\n2. Return a bike\n3. Exit\n```\n\nNote that there's an empty line at the start.", "hints": [ "Use the `echo` command with the `-e` flag and line breaks (`\\n`) to produce the suggested output", "Without the words, it looks like this: `echo -e \"\\n1. \\n2. \\n3. \"`", "Run your script if you need to see if the output matches", "Add `echo -e \"\\n1. Rent a bike\\n2. Return a bike\\n3. Exit\"` to your function" ] } ] }, { "id": "640", "title": "Run the file", "summary": "", "content": "", "steps": [ { "id": "640.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "e73d790e8351b08026a49441a9ed22c4a42b6951" ] }, "content": "Run the file to make sure it worked.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "650", "title": "Read MAIN_MENU_SELECTION", "summary": "", "content": "", "steps": [ { "id": "650.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "05b8292e94bf199a21c0bd1145342f2a3c0a1ee7" ] }, "content": "You have some options displaying. Next, you need to get input from whoever is using the program. Use the `read` command to read input into a variable called `MAIN_MENU_SELECTION` below the options.", "hints": [ "Here's an example: `read `", "Here's what the code looks like: `read MAIN_MENU_SELECTION`", "Add the code at the bottom of the `MAIN_MENU` function", "The `MAIN_MENU` function should look like this:\n```sh\nMAIN_MENU() {\n echo \"How may I help you?\"\n echo -e \"\\n1. Rent a bike\\n2. Return a bike\\n3. Exit\"\n read MAIN_MENU_SELECTION\n}\n```" ] } ] }, { "id": "660", "title": "Add RENT_MENU", "summary": "", "content": "", "steps": [ { "id": "660.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "ac94001dfbd340d9314b6c68c8c4e441d2fb6cb4" ] }, "content": "When an option gets entered, you need to take a user to one of those other menus. Add an empty `RENT_MENU` function below the `MAIN_MENU` function.", "hints": [ "Make sure the `RENT_MENU` function is below the `MAIN_MENU` function and above where you call `MAIN_MENU`", "Add this in the suggested area:\n```sh\nRENT_MENU() {\n\n}\n```" ] } ] }, { "id": "670", "title": "Add echo Rent Menu", "summary": "", "content": "", "steps": [ { "id": "670.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "288e44a83a12207f99b425c7653a3b7512aced7e" ] }, "content": "For the time being, just echo `Rent Menu` in the function so you can see if it's working.", "hints": [ "Don't use any flags with the command", "Add `echo \"Rent Menu\"` in the `RENT_MENU` function" ] } ] }, { "id": "680", "title": "Add RETURN_MENU function", "summary": "", "content": "", "steps": [ { "id": "680.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "734a42a5582ee970472b4e7cde0aad2add984ed7" ] }, "content": "Add an empty `RETURN_MENU` function below the `RENT_MENU` function for when a user enters the option to return a bike.", "hints": [ "Make sure the `RETURN_MENU` function is below the `RENT_MENU` function and above where you call `MAIN_MENU`", "Add this in the suggested area:\n```sh\nRETURN_MENU() {\n\n}\n```" ] } ] }, { "id": "690", "title": "Add echo Return Menu", "summary": "", "content": "", "steps": [ { "id": "690.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "d159ceb748fcdbe37a215970aa719a6f051fe290" ] }, "content": "Use `echo` to print `Return Menu` in the function you just added. You will change these later.", "hints": [ "Don't use any flags with the command", "Add `echo \"Return Menu\"` in the `RETURN_MENU` function" ] } ] }, { "id": "700", "title": "Add EXIT function", "summary": "", "content": "", "steps": [ { "id": "700.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "cdf11396c5e7632f7d0258259baf0f650cd026a6" ] }, "content": "Add an empty `EXIT` function below the `RETURN_MENU` function for when a user wants to exit the program.", "hints": [ "Make sure the `EXIT` function is below the `RETURN_MENU` function and above where you call `MAIN_MENU`", "Add this in the suggested area:\n```sh\nEXIT() {\n\n}\n```" ] } ] }, { "id": "710", "title": "Add EXIT Message", "summary": "", "content": "", "steps": [ { "id": "710.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "fa0ff5fa555407c5e71cc0fc7f982c144e08deec" ] }, "content": "This one probably doesn't need a placeholder message. In the `EXIT` function, use `echo` to print `Thank you for stopping in.` with a new line at the beginning and end of the message.", "hints": [ "The newline character is `\\n`", "Use double quotes around the message so the new lines are printed", "Here's an example: `echo -e \"\\n\\n\"`", "Add `echo -e \"\\nThank you for stopping in.\\n\"` to the `EXIT` function" ] } ] }, { "id": "720", "title": "Add case statement to `MAIN_MENU`", "summary": "", "content": "", "steps": [ { "id": "720.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "b3b43d9f68b82fda2ef60e4c28478de76da93f30" ] }, "content": "When a user enters an option at the main menu, you want to take them to the appropriate sub-menu. You can use a `case` statement for this. Here's an example:\n\n```sh\ncase EXPRESSION in\n PATTERN) STATEMENTS ;;\n PATTERN) STATEMENTS ;;\n PATTERN) STATEMENTS ;;\n *) STATEMENTS ;;\nesac\n```\n\nThe expression you want is the `$MAIN_MENU_SELECTION` variable. You are expecting it to be a `1`, `2`, or `3` for your various menus. Add a `case` statement that takes users to their corresponding menus. The `*` is for when anything else is entered. Take users to the `MAIN_MENU` when the variable isn't a `1`, `2`, or `3`.", "hints": [ "Add the `case` statement in the `MAIN_MENU` function below the `read MAIN_MENU_SELECTION` line", "Here's how it starts:\n```sh\ncase $MAIN_MENU_SELECTION in\n 1) RENT_MENU ;;\n```", "Add this case statement below the;\n```sh\ncase $MAIN_MENU_SELECTION in\n 1) RENT_MENU ;;\n 2) RETURN_MENU ;;\n 3) EXIT ;;\n *) MAIN_MENU ;;\nesac\n```" ] } ] }, { "id": "730", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "730.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "370882ee5212559f71fabd98523f7e0cd904fe05" ] }, "content": "Run the script a few times and try out the different menus. Be sure to enter something other than one of the options to go to the main menu.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "740", "title": "Add arg to MAIN_MENU call in case", "summary": "", "content": "", "steps": [ { "id": "740.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "3ce7b6e824cc75d4d21a18ee07088eccc0ee2eb1" ] }, "content": "Add an argument to where you call `MAIN_MENU` in the `case` statement. It should be `Please enter a valid option.`. The next step will adjust the function so the message is printed when a user enters an invalid option.", "hints": [ "Here's an example: `FUNCTION_CALL \"\"`", "Here's how the function call should look:\n```sh\n *) MAIN_MENU \"Please enter a valid option.\" ;;\n```", "The whole `case` statement should look like this:\n```sh\ncase $MAIN_MENU_SELECTION in\n 1) RENT_MENU ;;\n 2) RETURN_MENU ;;\n 3) EXIT ;;\n *) MAIN_MENU \"Please enter a valid option.\" ;;\nesac\n```" ] } ] }, { "id": "750", "title": "Add if $1 to MAIN_MENU", "summary": "", "content": "", "steps": [ { "id": "750.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "9f794657092abfb56e5bc66f321830fc541da70a" ] }, "content": "At the top of the `MAIN_MENU` function, add an `if` condition that checks if there's an argument (`$1`) passed to the function. If there is, print the message with a new line in front of it.", "hints": [ "Here's an example of an `if`:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition you want is `$1`", "Use `echo` with the `-e` flag and a new line character (`\\n`) to print the argument with a new line at the beginning in the `` area", "Here's an example of that part: `echo -e \"\\n\"`", "The `if` statement should look like this:\n```sh\nif [[ $1 ]]\nthen\n echo -e \"\\n$1\"\nfi\n```", "Make sure to put it at the top of the `MAIN_MENU` function" ] } ] }, { "id": "760", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "760.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "3d402f1c5a2a41487f5658cc1b88448924c1a55c" ] }, "content": "Run the script and enter an invalid option to see the message. Exit the program when you are done.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "850", "title": "Delete echo Rent Menu", "summary": "", "content": "", "steps": [ { "id": "850.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "b5af5f6edadd5e4b31fbb7175e44e4709de1a55c" ] }, "content": "Looks good. Delete the `echo \"Rent Menu\"` from the `RENT_MENU` function so you can start adding the ability to rent a bike from the database.", "hints": [ "The `RENT_MENU` function should be empty", "The `RENT_MENU` function should look like this:\n```sh\nRENT_MENU() {\n\n}\n```" ] } ] }, { "id": "860", "title": "Add comments to RENT_MENU", "summary": "", "content": "", "steps": [ { "id": "860.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "26688709e76885fb70990987f947cbd47bcdbb5d" ] }, "content": "In the `RENT_MENU` function, add three single line comments; `get available bikes`, `if no bikes available`, and `send to main menu`, in that order.", "hints": [ "Here's an example of a single line comment: `# `", "The `RENT_MENU` function should look like this:\n```sh\nRENT_MENU() {\n # get available bikes\n\n # if no bikes available\n\n # send to main menu\n\n}\n```" ] } ] }, { "id": "920", "title": "Add PSQL Variable", "summary": "", "content": "", "steps": [ { "id": "920.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "432d1478bd352d0586b0357c440179edab96d281" ] }, "content": "To get the bikes available, you need to query the database from your script. Below the \"shebang\", add a `PSQL` variable that looks like this: `PSQL=\"psql -X --username=freecodecamp --dbname=bikes --tuples-only -c\"`. You will then be able to use it to query the database like this: `$($PSQL \"\")`.", "hints": [ "Add the suggested variable below the \"shebang\" and above where you print the `Bike Rental Shop` line" ] } ] }, { "id": "970", "title": "Add AVAILABLE_BIKES", "summary": "", "content": "", "steps": [ { "id": "970.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "af74f4587fa666f72f1c88503b5718c7b1aa48a3" ] }, "content": "Below the `get available bikes` comment. Create an `AVAILABLE_BIKES` variable that gets the `bike_id`, `type`, and `size` columns from the `bikes` table for the bikes that are available. Order the results by their `bike_id` column. Here's an example: `AVAILABLE_BIKES=$($PSQL \"\")`", "hints": [ "Use the `SELECT`, `FROM`, `WHERE`, and `ORDER BY` keywords in your query", "Get the three suggested columns in the same order they are listed; `bike_id, type, size`", "The condition you want is `WHERE available = true`", "Without the keywords, the query looks like this: `bike_id, type, size bikes available = true bike_id`", "The query should be `SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id`", "Add `AVAILABLE_BIKES=$($PSQL \"SELECT bike_id, type, size FROM bikes WHERE available = true ORDER BY bike_id\")` below the `get available bikes` comment" ] } ] }, { "id": "980", "title": "echo AVAILABLE_BIKES", "summary": "", "content": "", "steps": [ { "id": "980.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "2e5e7891f1774527cfaa5ad9d4ba43eb338e9057" ] }, "content": "Below the new variable, use `echo` to print it. Place it in double quotes so it prints any new lines.", "hints": [ "Here's an example: `echo \"\"`", "Use the variable with `$AVAILABLE_BIKES`", "Add `echo \"$AVAILABLE_BIKES\"` to the suggested area" ] } ] }, { "id": "990", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "990.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "f7f927a4e68a78ff5fc6da02ab94b66f28c63ade" ] }, "content": "Run your script and go to the rent menu to see if the available bikes are being printed.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "993", "title": "psql UPDATE bikes SET available = false", "summary": "", "content": "", "steps": [ { "id": "993.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "70bce96f224aee7c063adf1df97fbc480870156c" ] }, "content": "Awesome. In the psql prompt, set the `available` column to `false` for all the bikes so you can see what it prints when there's no bikes available.", "hints": [ "Use the `UPDATE`, `SET`, and `WHERE` keywords", "Here's an example: `UPDATE SET = WHERE `", "You want to set `available` to `false` for columns that are `true`", "After the `SET` can look like this: `available = false WHERE available = true`", "Try entering `UPDATE bikes SET available = false WHERE available = true;` in the psql prompt", "Type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in. I recommend \"splitting\" the terminal so you can have one for bash commands and one for psql commands. You can do that by clicking the \"hamburger\" menu at the top left of the window, going to the \"terminal\" section, and clicking \"split terminal\"." ] } ] }, { "id": "995", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "995.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d4c18e9f06707060cba199fd46d8402d421b7cd3" ] }, "content": "Run your script and go to the rent menu to see the output.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure it's the regular terminal and not the psql one", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1000", "title": "Add if -z AVAILABLE_BIKES", "summary": "", "content": "", "steps": [ { "id": "1000.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "477a415fcc3b2ccd5b90742db15f44ed0c282cde" ] }, "content": "So if there's no bike available, the variable will be empty. In the script, below the `if no bikes available` comment, add an `if` condition that checks if the variable is empty. Use `-z` to check if it's empty. Place the `send to main menu` comment in its `STATEMENTS` area.", "hints": [ "Use `-z ` to see if a variable is empty", "Here's an example:\n```sh\nif [[ -z ]]\nthen\n \nfi\n```", "The `if` condition should look like this:\n```sh\nif [[ -z $AVAILABLE_BIKES ]]\nthen\n # send to main menu\nfi\n```", "Make sure it's right below the suggested comment" ] } ] }, { "id": "1010", "title": "Add MAIN_MENU Sorry, we don't have any bikes available right now", "summary": "", "content": "", "steps": [ { "id": "1010.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "7512d7e2db20bb3cd6dfd134f848ccfe213e4e88" ] }, "content": "Below the comment in the `if` you just added. Send users to the main menu and give them the message, `Sorry, we don't have any bikes available right now.`", "hints": [ "Here's an example `MAIN MENU \"\"`", "Make sure it's in the `if` condition below the `send to main menu` comment", "The function call should look like this: `MAIN_MENU \"Sorry, we don't have any bikes available right now.\"`", "The `if` condition should look like this:\n```sh\nif [[ -z $AVAILABLE_BIKES ]]\nthen\n # send to main menu\n MAIN_MENU \"Sorry, we don't have any bikes available right now.\"\nfi\n```" ] } ] }, { "id": "1020", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1020.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "932075f05d71ab11fef33b8d390623e43f31c0d7" ] }, "content": "Run the script and go to the rent menu to see the message. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1100", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1100.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "3621fd0908e7c2e1a0c3324da8810e336d02ea2c" ] }, "content": "If no bikes are available, you will get that message. Add an `else` to the `if` condition for when there is bikes available. In it, add four single line comments; `display available bikes`, `ask for bike to rent`, `if input is not a number`, and `send to main menu`.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "An `if/else` statement looks like this:\n```sh\nif [[ ]]\nthen\n \nelse\n \nfi\n```", "The `else` should look like this:\n```sh\nelse\n # display available bikes\n\n # ask for bike to rent\n\n # if input is not a number\n\n # send to main menu\n\n```", "The whole `if` should look like this:\n```sh\nif [[ -z $AVAILABLE_BIKES ]]\nthen\n # send to main menu\n MAIN_MENU \"Sorry, we don't have any bikes available right now.\"\nelse\n # display available bikes\n\n # ask for bike to rent\n\n # if input is not a number\n\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1105", "title": "Add echo Here are the bikes we have available", "summary": "", "content": "", "steps": [ { "id": "1105.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "144dc759856cf1f5a6fb92ad42147afe3fc88ae0" ] }, "content": "Below the `display available bikes` comment you just added, use `echo` to print `Here are the bikes we have available:` with a new line in front of the message", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nHere are the bikes we have available:\"` below the suggested comment" ] } ] }, { "id": "1110", "title": "Move echo AVAILABLE_BIKES", "summary": "", "content": "", "steps": [ { "id": "1110.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "e728ff5488729ede9145010e8c318cc7d303f087" ] }, "content": "Move the `echo` command that prints all the available bikes below the message you just added.", "hints": [ "It's the `echo $AVAILABLE_BIKES` command", "It should be below the `Here are the bikes we have available:` message", "You should only print the bikes available in that one spot", "Place the `echo \"$AVAILABLE_BIKES\"` line in the suggested spot" ] } ] }, { "id": "1115", "title": "psql UPDATE bikes SET all != BMX to TRUE", "summary": "", "content": "", "steps": [ { "id": "1115.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "fcaffb511e24a014f8d7544725f87ec9d201f252" ] }, "content": "In the psql prompt, set all the bikes, except for the `BMX` bikes, back to true so you can see a list of bikes to rent.", "hints": [ "Use the `UPDATE`, `SET`, and `WHERE` keywords", "Here's an example: `UPDATE
SET = WHERE `", "You want to set `available` to `true` for columns that don't have a `type` of `BMX`", "You can use the `!=` operator to check for columns not equal to a value", "After the `SET` can look like this: `available = true WHERE type != 'BMX'`", "Try entering `UPDATE bikes SET available = true WHERE type != 'BMX';` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1130", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1130.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "34d930d766390ea5125819f0b2bab223d544dcb6" ] }, "content": "Run the script and go to the rent menu to see the list of bikes available.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1140", "title": "pipe AVAILABLE_BIKES into while loop", "summary": "", "content": "", "steps": [ { "id": "1140.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "47413f775d79b97e90fc0ae4b03208772a8346de" ] }, "content": "Instead of directly printing the list, `pipe` the output into a `while` loop that reads each line. Here's how that looks:\n\n```sh\necho \"$AVAILABLE_BIKES\" | while read \ndo\n \ndone\n```\n\nIt will read the first line of your `AVAILABLE_BIKES` variable into the five variables. Each variable being the next word in the line. Read each line into variables, `BIKE_ID BAR TYPE BAR SIZE`. In the `` area, use `echo` to print the `BIKE_ID`, `TYPE`, and `SIZE` variables, in that order.", "hints": [ "The first line should be `echo \"$AVAILABLE_BIKES\" | while read BIKE_ID BAR TYPE BAR SIZE`", "The `` area looks like this: `echo \"$BIKE_ID $TYPE $SIZE\"`", "Here's how it should look:\n```sh\necho \"$AVAILABLE_BIKES\" | while read BIKE_ID BAR TYPE BAR SIZE\ndo\n echo \"$BIKE_ID $TYPE $SIZE\"\ndone\n```" ] } ] }, { "id": "1142", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1142.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "dfdc796b145f717f20d01fbb5b16a8f90291d06c" ] }, "content": "Run the script and go to the rent menu again to see if it's working.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1145", "title": "Adjust Available Bikes Display", "summary": "", "content": "", "steps": [ { "id": "1145.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "8e5bb742ef39a6d6cf654f48c28f66938fa913de" ] }, "content": "It's working :smile: Adjust the echo command that prints the bike info so that the first line printed would look like this: `1) 27\" Mountain Bike`. The rest would look the same, but with their bike info. Make sure to escape any characters you need to.", "hints": [ "Be sure to use double quotes and escape the `\"` after `SIZE`", "Run your script and check the output if you want to see if it matches the suggestion", "Escape a `\"` with `\\\"`", "Here's an example: `echo \") \" Bike\"`", "Make the suggested line look like this: `echo \"$BIKE_ID) $SIZE\\\" $TYPE Bike\"`", "The whole loop should look like this:\n```sh\necho \"$AVAILABLE_BIKES\" | while read BIKE_ID BAR TYPE BAR SIZE\ndo\n echo \"$BIKE_ID) $SIZE\\\" $TYPE Bike\"\ndone\n```" ] } ] }, { "id": "1150", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1150.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "c473a1cc396e4f71a88d44ec98bacf96666f4b1e" ] }, "content": "Run the script and go to the rent menu again to see what it looks like now.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1160", "title": "Add echo Which one would you like to rent?", "summary": "", "content": "", "steps": [ { "id": "1160.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "39a23499f881b2b74e37e3a1d3c9ea9e1039106c" ] }, "content": "That's better. Below the `ask for bike to rent` comment, print `Which one would you like to rent?` with a new line in front of it.", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nWhich one would you like to rent?\"` below the suggested comment" ] } ] }, { "id": "1162", "title": "read BIKE_ID_TO_RENT", "summary": "", "content": "", "steps": [ { "id": "1162.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "74291e1d89a099e306cf0ac44b7b4997bb4e74ba" ] }, "content": "Just below that, add a command to `read` input into a variable named `BIKE_ID_TO_RENT`.", "hints": [ "Here's an example: `read `", "Add this to the suggested area: `read BIKE_ID_TO_RENT`" ] } ] }, { "id": "1164", "title": "[[ a =~ [0-9] ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1164.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d21ba02209f124ff95e0a4376f052ffd7328f3ab" ] }, "content": "Next, you want to find out how to test if the user input is a number. In the terminal, enter `[[ a =~ [0-9] ]]; echo $?` to see if `a` is a number. The conditional expression will run, and `echo $?` will print the exit code of it (the last command).", "hints": [ "Enter `[[ a =~ [0-9] ]]; echo $?` in the terminal", "It's the regular terminal, not the psql one" ] } ] }, { "id": "1165", "title": "echo [[ a1 =~ [0-9] ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1165.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "b23c65784d434f242f0bc7a8b9ca56b3000b6652" ] }, "content": "It printed `1` for false. Meaning that `a` did not match the pattern [0-9], or `a` did not contain a number from `0-9`. Enter the same commands, but check if `a1` matches the pattern.", "hints": [ "The previous command was `[[ a =~ [0-9] ]]; echo $?`", "Enter `[[ a1 =~ [0-9] ]]; echo $?` in the terminal" ] } ] }, { "id": "1166", "title": "echo [[ a1 =~ ^[0-9]$ ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1166.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "fcef6da1fc86dc71d3fedd962597c4ce51f70c14" ] }, "content": "That printed `0` for true. `a1` does contain a number from `0-9`. Enter the same command, but change the pattern to `^[0-9]$`. The `^` signifies the start of the pattern, and `$` means the end. So the input will have to start, contain a number `0-9`, and end.", "hints": [ "The previous command was `[[ a1 =~ [0-9] ]]; echo $?`", "Enter `[[ a1 =~ ^[0-9]$ ]]; echo $?` in the terminal" ] } ] }, { "id": "1167", "title": "echo [[ 1 =~ ^[0-9]$ ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1167.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d69475f2024fa06ade4a0c5f99278d663f418a18" ] }, "content": "`1` for false. `a1` does not match the pattern. Using the same syntax, check if `1` matches the pattern.", "hints": [ "The previous command was `[[ a1 =~ ^[0-9]$ ]]; echo $?`", "Enter `[[ 1 =~ ^[0-9]$ ]]; echo $?` in the terminal" ] } ] }, { "id": "1168", "title": "echo [[ 11 =~ ^[0-9]$ ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1168.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "b329beae880ebc7d687274f310c41796ffd115ba" ] }, "content": "`1` does match the pattern. It starts, contains a number, and ends. Check if `11` matches the same pattern.", "hints": [ "The previous command was `[[ 1 =~ ^[0-9]$ ]]; echo $?`", "Enter `[[ 11 =~ ^[0-9]$ ]]; echo $?` in the terminal" ] } ] }, { "id": "1169", "title": "echo [[ 11 =~ ^[0-9]+$ ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1169.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "a29fb5b531ad9d313b2eedf1b7da1f44c6f412cd" ] }, "content": "That did not match because the pattern only allows a single number. Add a `+` after the `[0-9]` to allow any strings that start, contain one or more numbers, and end.", "hints": [ "Enter the previous command with the suggested changed", "The previous command was `[[ 11 =~ ^[0-9]$ ]]; echo $?`", "Enter `[[ 11 =~ ^[0-9]+$ ]]; echo $?` in the terminal" ] } ] }, { "id": "1170", "title": "echo [[ ! 11 =~ ^[0-9]+$ ]]; echo $?", "summary": "", "content": "", "steps": [ { "id": "1170.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "2a29650dfcf7e3ea486dab34b882cf8a196d6ff6" ] }, "content": "So that pattern will match any positive integers. You want to check if the input is not a number. Add `!` in front of the comparison of the previous command to do that.", "hints": [ "Enter the previous command with the suggested changed", "The previous command was `[[ 11 =~ ^[0-9]+$ ]]; echo $?`", "Enter `[[ ! 11 =~ ^[0-9]+$ ]]; echo $?` in the terminal" ] } ] }, { "id": "1176", "title": "Add if [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]", "summary": "", "content": "", "steps": [ { "id": "1176.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "6d2cb8c42aa99956cb1492fa025e14a9dee81c23" ] }, "content": "Back in your script, below the `if input is not a number` comment, add an `if` condition that checks if the input is not a number using the method you just practiced. Add the `send to main menu` comment in the `then` area of the `if`.", "hints": [ "You want to check if the `$BIKE_ID_TO_RENT` variable is not a number", "You entered `[[ ! 11 =~ ^[0-9]+$ ]]; echo $?` in the terminal on the last step", "Here's an example:\n```sh\nif [[ ]]\nthen\n # send to main menu\nfi\n```", "The condition you want is `[[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]`", "Add this in the suggestion area:\n```sh\nif [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]\nthen\n # send to main menu\nfi\n```" ] } ] }, { "id": "1177", "title": "Add MAIN_MENU That is not a valid bike number", "summary": "", "content": "", "steps": [ { "id": "1177.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "1cac94070cbd4da85311c25d4b62a0094aedf2dd" ] }, "content": "If the `$BIKE_ID_TO_RENT` variable is not a number, add the code to send users to the main menu with the message, `That is not a valid bike number.`", "hints": [ "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"That is not a valid bike number.\"` below the `send to main menu` comment" ] } ] }, { "id": "1178", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1178.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "48f2c498b2d9d547101fcb12b6cabe53399bfa04" ] }, "content": "Run the script, go to the rent menu, and enter something that isn't a number to make sure it is working. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1179", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1179.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "baa3cf6b17a03aadc643b360adf5e570289d0fd1" ] }, "content": "Add an `else` area for when the input is a number. Add these three single line comments in it; `get bike availability`, `if not available`, `send to main menu`.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "An `if/else` statement looks like this:\n```sh\nif [[ ]]\nthen\n \nelse\n \nfi\n```", "The `else` area should look like this:\n```sh\nelse\n # get bike availability\n\n # if not available\n\n # send to main menu\n\n```", "The whole `if` should look like this:\n```sh\nif [[ ! $BIKE_ID_TO_RENT =~ ^[0-9]+$ ]]\nthen\n # send to main menu\n MAIN_MENU \"That is not a valid bike number.\"\nelse\n # get bike availability\n\n # if not available\n\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1180", "title": "Add BIKE_AVAILABILITY", "summary": "", "content": "", "steps": [ { "id": "1180.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "3e58620082d85bd313d85b82a247ee849ea1692e" ] }, "content": "Below the `get bike availability` comment you just added, create a `BIKE_AVAILABILITY` variable. Set it equal to a query that gets the `available` column from the `bikes` table for the input. Also, make sure to only get the row if it is available.", "hints": [ "Here's an example: `BIKE_AVAILABILITY=$($PSQL \"\")`", "Use the `SELECT`, `FROM`, `WHERE`, and `AND` keywords", "Here's an example of the query: `SELECT FROM
WHERE AND `", "You only want the `available` column for the bike with a `bike_id` equal to the `$BIKE_ID_TO_RENT` variable and only if the bike is available", "You want two conditions, `WHERE bike_id = $BIKE_ID_TO_RENT AND available = true`", "Add `BIKE_AVAILABILITY=$($PSQL \"SELECT available FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT AND available = true\")` below the `get bike availability` comment" ] } ] }, { "id": "1190", "title": "Add echo BIKE_AVAILABILITY", "summary": "", "content": "", "steps": [ { "id": "1190.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "16a676e8c5d7408b626244eae7399370363d7c44" ] }, "content": "Right below the variable you just created, use echo to print it so you can see what it looks like.", "hints": [ "Print a variable like this: `echo $`", "The variable you want is `BIKE_AVAILABILITY`", "Add `echo $BIKE_AVAILABILITY` in the suggested area" ] } ] }, { "id": "1200", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1200.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "ad6701ab87f1bd840f0dc1fd1f5e12bb0e8b183d" ] }, "content": "Run the script a few times, go to the rent menu, enter a bike that is available and one that isn't. You should have some `BMX` bikes that aren't available.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1210", "title": "Add if -z BIKE_AVAILABILITY", "summary": "", "content": "", "steps": [ { "id": "1210.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "7d53e61e6a1a3b29eaae3344f1f5130d243bb110" ] }, "content": "The variable will be `t` or empty. Below the `if not available` comment, add an `if` condition that checks if it's empty. Put the `send to main menu` comment in it's statements area.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition you want is `-z $BIKE_AVAILABILITY`", "Place the `# send to main menu` comment in the `` area", "The `if` condition should look like this:\n```sh\nif [[ -z $BIKE_AVAILABILITY ]]\nthen\n # send to main menu\nfi\n```" ] } ] }, { "id": "1215", "title": "Add MAIN_MENU That bike is not available", "summary": "", "content": "", "steps": [ { "id": "1215.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "a4b9d9c1442efc264dcb7f140c815014e9f3b531" ] }, "content": "In the `if` condition you just added, send users to the main menu with the message `That bike is not available.` if they input a number that isn't available.", "hints": [ "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"That bike is not available.\"` below the `send to main menu` comment" ] } ] }, { "id": "1220", "title": "Remove echo BIKE_AVAILABILITY", "summary": "", "content": "", "steps": [ { "id": "1220.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "d1ef9878ace4edcd4fe5b6355c3fda89b6755ff0" ] }, "content": "Remove the line where you print the `BIKE_AVAILABILITY` variable. You don't need it anymore.", "hints": [ "Remove the `echo $BIKE_AVAILABILITY` line" ] } ] }, { "id": "1230", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1230.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "35a744f28b687e398ae31ebdabb26c3ee7a2d839" ] }, "content": "Run the script and go to the rent menu, enter a bike that isn't available to make sure it's working. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1233", "title": "psql UPDATE bikes SET add to true", "summary": "", "content": "", "steps": [ { "id": "1233.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "b4ed70f7f7a66d8998a7cb6d5c981487a9672e0c" ] }, "content": "In the psql prompt, set all the bikes availability back to true.", "hints": [ "Use the `UPDATE`, `SET`, and `WHERE` keywords", "Here's an example: `UPDATE
SET = WHERE `", "You want to set `available` to `true` for all the bikes", "After the `SET` can look like this: `available = true WHERE available = false`", "Try entering `UPDATE bikes SET available = true WHERE available = false;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1236", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1236.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "fad950af692b6bc3c7920e20177d25937c6fb2c5" ] }, "content": "In your script, add an `else` for when a bike is available. Add these four comments in the `else` area `get customer info`, `if customer doesn't exist`, `get new customer name`, and `insert new customer`.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "An `if/else` statement looks like this:\n```sh\nif [[ ]]\nthen\n \nelse\n \nfi\n```", "The `else` area should look like this:\n```sh\nelse\n # get customer info\n\n # if customer doesn't exist\n\n # get new customer name\n\n # insert new customer\n\n```", "The whole `if` should look like this:\n```sh\nif [[ -z $BIKE_AVAILABILITY ]]\nthen\n # send to main menu\n MAIN_MENU \"That bike is not available.\"\nelse\n # get customer info\n\n # if customer doesn't exist\n\n # get new customer name\n\n # insert new customer\n\nfi\n```" ] } ] }, { "id": "1240", "title": "Add echo What's your phone number?", "summary": "", "content": "", "steps": [ { "id": "1240.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "8049f86b0078d4ab5bbae25b7e63f84104e7ace6" ] }, "content": "As the comments say, you need to get the customer info and find out if they are an existing customer. Below the `get customer info` comment, print `What's your phone number?` with a new line in front of it.", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nWhat's your phone number?\"` below the suggested comment" ] } ] }, { "id": "1250", "title": "read PHONE_NUMBER", "summary": "", "content": "", "steps": [ { "id": "1250.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "ccd8767ab3a1035f388617f17e7e1ca4829a9c2c" ] }, "content": "Below the line you just printed, read input into a `PHONE_NUMBER` variable. Since the phone number is unique, you can use it to identify a customer.", "hints": [ "Here's an example: `read `", "Add `read PHONE_NUMBER` to the suggested area", "Add it below where you print `What's your phone number?`" ] } ] }, { "id": "1260", "title": "Add CUSTOMER_NAME", "summary": "", "content": "", "steps": [ { "id": "1260.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "e3e4a0e236cfe3eb0f02f3917b3ba7a4d8ec877e" ] }, "content": "With the customer's phone number, you can get their name. Below where you get the phone number, create a `CUSTOMER_NAME` variable that gets the customers name from the database using the phone number.", "hints": [ "Query the database to set the `CUSTOMER_NAME` variable", "Here's an example: `CUSTOMER_NAME=$($PSQL \"\")`", "Use the `SELECT`, `FROM` and `WHERE` keywords for your query", "You want only the `name` column from the `customers` table", "The condition you want is `phone = '$PHONE_NUMBER'`", "The query should look like this: `SELECT name FROM customers WHERE phone = '$PHONE_NUMBER'`", "Add `CUSTOMER_NAME=$($PSQL \"SELECT name FROM customers WHERE phone = '$PHONE_NUMBER'\")` below the `read PHONE_NUMBER` line" ] } ] }, { "id": "1265", "title": "Add if -z CUSTOMER_NAME", "summary": "", "content": "", "steps": [ { "id": "1265.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "774913001c116ef8cb0bb8de9ba91ea98d15759f" ] }, "content": "If the customer is in the database with the phone number used, the variable will be set to the name. If not, it will be empty. Add an `if` condition below the `if customer doesn't exist` comment that checks if the variable is empty. Place the next two comments in the `then` area.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition you want is `-z $CUSTOMER_NAME`", "Place the `# get new customer name` and `# insert new customer` comments in the `` area", "The `if` condition should look like this:\n```sh\nif [[ -z $CUSTOMER_NAME ]]\nthen\n # get new customer name\n\n # insert new customer\n\nfi\n```", "Make sure it's below the `if customer doesn't exist` comment" ] } ] }, { "id": "1270", "title": "Add echo What's your name?", "summary": "", "content": "", "steps": [ { "id": "1270.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "132d28e9e4ccd2e0740c29e66ea1186ffe064875" ] }, "content": "If the customer isn't in the database, you need to get their name so you can add them. Below the `get new customer name` comment, print `What's your name?` with a new line in front of the message.", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nWhat's your name?\"` below the suggested comment" ] } ] }, { "id": "1280", "title": "read CUSTOMER_NAME", "summary": "", "content": "", "steps": [ { "id": "1280.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "3eb5bf51ffdf40670c4fca162cca2668fad97172" ] }, "content": "Below the question you just printed, read input into a variable named `CUSTOMER_NAME`.", "hints": [ "Here's an example: `read `", "Add `read CUSTOMER_NAME` to the suggested area", "Add it below where you print `What's your name?`" ] } ] }, { "id": "1290", "title": "Add INSERT_CUSTOMER_RESULT", "summary": "", "content": "", "steps": [ { "id": "1290.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "61bdc8c0f4d1b7169a288651a50db6f7924c64ff" ] }, "content": "You have the two pieces of information you need. Below the `insert new customer` comment, create an `INSERT_CUSTOMER_RESULT` variable that inserts the customer into the database.", "hints": [ "Here's an example: `INSERT_CUSTOMER_RESULT=$($PSQL \"\")`", "View the `customers` table in the psql prompt with `\\d customers` to see the columns you need to add data to", "Be sure to use single quotes around `VARCHAR` values", "The query looks similar to this: `INSERT INTO customers(column1, column2) VALUES('value1', 'value2')`", "You want to use the `CUSTOMER_NAME` and `PHONE_NUMBER` variables for the values", "Here's the query: `INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')`", "Add `INSERT_CUSTOMER_RESULT=$($PSQL \"INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')\")` below the `insert new customer` comment" ] } ] }, { "id": "1300", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1300.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "b5e221bb19f7d3becec4944ac5aa32331da0ee0e" ] }, "content": "Run your script and go to the rent menu. Pick a bike to rent, then enter `555-5555` when it asks for a phone number, and `Me` when it asks for your name.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Follow the instructions closely", "Make sure to use `555-5555` for the phone number and `Me` for the name", "The database should have a customer with `555-5555` as their phone number, and `Me` as their name in it" ] } ] }, { "id": "1310", "title": "psql SELECT * FROM customers", "summary": "", "content": "", "steps": [ { "id": "1310.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "4513292f444b8372f41f785835f5a70f057bc3e8" ] }, "content": "That should have added a new customer to the database. In the psql prompt, view all the data in the `customers` table to see if it's working.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM customers;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1311", "title": "psql SELECT * FROM rentals", "summary": "", "content": "", "steps": [ { "id": "1311.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "e67c11af54fc87438267e5e300bd56ac2dd7ccbb" ] }, "content": "Excellent. View all the data in the rentals table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM rentals;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1312", "title": "psql SELECT * FROM bikes", "summary": "", "content": "", "steps": [ { "id": "1312.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "e2a993c19ac15a64675dd0be28998ab5582e64c1" ] }, "content": "So you still need to add the rental to the rentals table when a bike is picked out. View all the data in the `bikes` table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM bikes;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1315", "title": "Add comments", "summary": "", "content": "", "steps": [ { "id": "1315.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "2ee2e704443fb5ee0d2d874cd72c10f745603618" ] }, "content": "And set the `available` column to false for the bike rented. Below the end of the `if` statement that inserts a new customer, add five more comments; `get customer_id`, `insert bike rental`, `set bike availability to false`, `get bike info`, and `send to main menu`", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "The comments should be below (not in) the `if [[ -z $CUSTOMER_NAME ]]` statement", "The comments should look like this:\n```sh\n if [[ -z $CUSTOMER_NAME ]]\n then\n # get new customer name\n echo -e \"\\nWhat's your name?\"\n read CUSTOMER_NAME\n\n # insert new customer\n INSERT_CUSTOMER_RESULT=$($PSQL \"INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$PHONE_NUMBER')\")\n fi\n\n # get customer_id\n\n # insert bike rental\n\n # set bike availability to false\n\n # get bike info\n\n # send to main menu\n\n```" ] } ] }, { "id": "1320", "title": "Add CUSTOMER_ID", "summary": "", "content": "", "steps": [ { "id": "1320.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "6fe6265e744ce68e9c38733d4745be53a6c7f241" ] }, "content": "You're getting close to done with the rent functionality. To add a rental to the database, you need the customer ID. Below the `get customer_id` comment, create a `CUSTOMER_ID` variable that gets the `customer_id` using the phone number.", "hints": [ "Here's an example: `CUSTOMER_ID=$($PSQL \"\")`", "You want to get the `customer_id` column from the customers table using the `PHONE_NUMBER` variable in your condition to get it", "The condition you want is `WHERE phone = '$PHONE_NUMBER'`", "The query looks like this: `SELECT customer_id FROM customers WHERE phone = '$PHONE_NUMBER'`", "Add `CUSTOMER_ID=$($PSQL \"SELECT customer_id FROM customers WHERE phone = '$PHONE_NUMBER'\")` below the `get customer_id` comment" ] } ] }, { "id": "1330", "title": "Add INSERT_RENTAL_RESULT", "summary": "", "content": "", "steps": [ { "id": "1330.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "a81dde960fe1f926303baa8a6318928704f36b8e" ] }, "content": "Now that you have the bike ID and customer ID, you can add the rental to the database. Below the `insert bike rental` comment, create a `INSERT_RENTAL_RESULT` variable that adds the rental to the database.", "hints": [ "Here's an example: `INSERT_RENTAL_RESULT=$($PSQL \"\")`", "View the `rentals` table by entering `\\d rentals` in the psql prompt to see what the columns are", "The query looks similar to this: `INSERT INTO rentals(column1, column2) VALUES(value1, value2)`", "You want to insert the `BIKE_ID_TO_RENT` and `CUSTOMER_ID` variables into the `bike_id` and `customer_id` columns", "The query should look like this: `INSERT INTO rentals(bike_id, customer_id) VALUES($BIKE_ID_TO_RENT, $CUSTOMER_ID)`", "Add `INSERT_RENTAL_RESULT=$($PSQL \"INSERT INTO rentals(customer_id, bike_id) VALUES($CUSTOMER_ID, $BIKE_ID_TO_RENT)\")` below the `insert bike rental` comment" ] } ] }, { "id": "1370", "title": "Add SET_TO_FALSE_RESULT", "summary": "", "content": "", "steps": [ { "id": "1370.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "5ab3a066a207c58a14b8284031125a062b0cfeaf" ] }, "content": "That should add the rental to the database. The last thing to do is set `available` to false for the bike. Below the `set bike availability to false` comment, create a `SET_TO_FALSE_RESULT` variable that does that.", "hints": [ "Here's an example: `SET_TO_FALSE_RESULT=$($PSQL \"\")`", "You want to use the `UPDATE`, `SET`, and `WHERE` keywords", "You want to set the `available` column to `false` for the `bike_id` of `BIKE_ID_TO_RENT`", "The query looks similar to this: `UPDATE
SET = WHERE `", "The query looks like this: `UPDATE bikes SET available = false WHERE bike_id = $BIKE_ID_TO_RENT`", "Add `SET_TO_FALSE_RESULT=$($PSQL \"UPDATE bikes SET available = false WHERE bike_id = $BIKE_ID_TO_RENT\")` below the `set bike availability to false` comment" ] } ] }, { "id": "1380", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1380.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "e75bd28046a426fdbaa62a6ac6e0fa7af8bbc541" ] }, "content": "Run the script and go to the rent menu. Pick the first bike on the list and enter `555-5555` when it asks for a phone number again. That phone number should already be in the database, so it won't ask for a name or insert a customer.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure to enter the correct bike number and phone number", "There should be a rental in the database for customer with phone number `555-5555` and name `Me`" ] } ] }, { "id": "1390", "title": "psql SELECT * FROM rentals", "summary": "", "content": "", "steps": [ { "id": "1390.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "5baa6d80f55cf5123efde4e7b08aa7beaa257cb5" ] }, "content": "In the psql prompt, view all the data in the `rentals` table. There should be a new rental.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM rentals;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1400", "title": "psql SELECT * FROM bikes ORDER BY bike_id", "summary": "", "content": "", "steps": [ { "id": "1400.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "553d03bda3652849e6cf27593d3494632d2d3398" ] }, "content": "The rental was added and the `date_rented` was filled in automatically. :smile: Next, view all the data in the `bikes` table. Order the results by `bike_id`", "hints": [ "Use the `SELECT`, `FROM`, and `ORDER BY` keywords with `*` to view all the data", "Enter `SELECT * FROM bikes ORDER BY bike_id;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1401", "title": "Add BIKE_INFO", "summary": "", "content": "", "steps": [ { "id": "1401.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "334d03eb459b810ff7beca43cb73eb6c6063f40f" ] }, "content": "The available column was set to false for the bike you rented. The last thing to do is give a nice message about the rental. Below the `get bike info` comment, create a `BIKE_INFO` variable that gets the `size` and `type`, in that order, of the bike rented.", "hints": [ "Here's an example: `BIKE_INFO=$($PSQL \"\")`", "You want to use the `SELECT`, `FROM`, and `WHERE` keywords", "Use the `BIKE_ID_TO_RENT` variable to find the needed info for the bike", "The query looks similar to this: `SELECT size, type FROM
WHERE `", "The condition you want is `WHERE bike_id = $BIKE_ID_TO_RENT`", "The query looks like this: `SELECT size, type FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT`", "Add `BIKE_INFO=$($PSQL \"SELECT size, type FROM bikes WHERE bike_id = $BIKE_ID_TO_RENT\")` below the `get bike info` comment" ] } ] }, { "id": "1402", "title": "Add echo BIKE_INFO", "summary": "", "content": "", "steps": [ { "id": "1402.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "8e1b8a4cfc38c733c08ed34ad5459283a9623145" ] }, "content": "Below the variable you just created, use `echo` to print it.", "hints": [ "Print a variable like this: `echo $`", "The variable you want is `BIKE_INFO`", "Add `echo $BIKE_INFO` in the suggested area" ] } ] }, { "id": "1403", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1403.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "617d8462293a57a1086d2301ca6fbbc567dfe060" ] }, "content": "Run the script again and go to the rent menu, there should now be one less bike displayed. Pick the next bike on the list and rent it using the customer with phone number `555-5555` again so you can see the variable.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "There should be at least two rentals for the customer with phone nummber `555-5555` and name `Me`" ] } ] }, { "id": "1404", "title": "echo '28 | Mountain' | sed 's/ /=/g'", "summary": "", "content": "", "steps": [ { "id": "1404.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "a9d593079693146072ece6d3e8ebfcc089962580" ] }, "content": "It should have printed `28 | Mountain`. The message you want to print after someone rents a bike would have said `I have put you down for the 28\" Mountain Bike, Me.`. You need to format that variable for the message. The `sed` command can be used to replace characters and patterns in text. It looks like this: `sed s///`. In the terminal, enter `echo '28 | Mountain' | sed 's/ /=/g'` to practice.", "hints": [ "Enter the suggested command in the terminal", "Not the psql one" ] } ] }, { "id": "1405", "title": "echo '28 | Mountain' | sed 's/ //g'", "summary": "", "content": "", "steps": [ { "id": "1405.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "c442bcb58f2f4656020e8d9a5a42e72c900c42f9" ] }, "content": "The command you used, \"piped\" a string (`28 | Mountain`) to the `sed` command, where it replaced all the spaces with `=`. Enter the same command, but replace all the spaces with nothing.", "hints": [ "The previous command was `echo '28 | Mountain' | sed 's/ /=/g'`", "Remove the `=` from the previous command", "Enter `echo '28 | Mountain' | sed 's/ //g'` in the terminal" ] } ] }, { "id": "1407", "title": "echo '28 | Mountain' | sed 's/ //'", "summary": "", "content": "", "steps": [ { "id": "1407.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "ae7737f3391c59f6d749db13ac394d88f965979f" ] }, "content": "The `g` regex flag stands for \"global\". It will replace all instance of the pattern. In this case, it replaced all the spaces. Enter the same command but without that flag.", "hints": [ "The previous command was `echo '28 | Mountain' | sed 's/ //g`", "Remove the `g` flag from the previous command", "Enter `echo '28 | Mountain' | sed 's/ //'` in the terminal" ] } ] }, { "id": "1408", "title": "echo '28 | Mountain' | sed 's/ |//'", "summary": "", "content": "", "steps": [ { "id": "1408.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "a70d4f8870aced183e372e671fbf5d89cb074fa4" ] }, "content": "That time, only the first instance of the pattern was replaced. The first space was removed. Enter the same command, but replace the first instance of  | (`|`) with nothing.", "hints": [ "The previous command was `echo '28 | Mountain' | sed 's/ //`", "You want to replace the space in the pattern of the last command with  | (`|`)", "Enter `echo '28 | Mountain' | sed 's/ |//'` in the terminal" ] } ] }, { "id": "1410", "title": "echo '28 | Mountain' | sed 's/ |/\"/'", "summary": "", "content": "", "steps": [ { "id": "1410.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "99c3414ed87fb230707c051ccf13820ca0bdb256" ] }, "content": "Enter the same command, but make the output look like how you want in the message, `28\" Mountain`.", "hints": [ "The previous command was `echo '28 | Mountain' | sed 's/ |//`", "Use `\"` as the character to replace  | (`|`) with", "Enter `echo '28 | Mountain' | sed 's/ |/\"/'` in the terminal" ] } ] }, { "id": "1411", "title": "Add echo BIKE_INFO | sed 's/ |/\"/'", "summary": "", "content": "", "steps": [ { "id": "1411.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "5511cec22c608eb218d552170aaf60cb52799015" ] }, "content": "Back in your script, where you `echo` the `BIKE_INFO`, pipe the output into a `sed` command that replaces  | (`|`) with `\"` so the text will read `\" `. `28 | Mountain` would become `28\" Mountain`, for instance.", "hints": [ "The previous command was `echo '28 | Mountain' | sed 's/ |/\"/'`", "You want to add the `| sed 's/ |/\"/'` part of the previous command after your `echo $BIKE_INFO` line", "Make the suggested area look like this:\n```sh\necho $BIKE_INFO | sed 's/ |/\"/'\n```" ] } ] }, { "id": "1413", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1413.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "682e81792804e7da949fc4b849e0368be07f3d83" ] }, "content": "Run the script and rent another bike using the customer with phone number `555-5555` again. Make sure the bike info printed looks like you want.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "The customer with phone number `555-5555` and name `Me` should have at least three bikes rented" ] } ] }, { "id": "1415", "title": "Add BIKE_INFO_FORMATTED", "summary": "", "content": "", "steps": [ { "id": "1415.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "93971417adebd40a37585f474bc6f03bccefd197" ] }, "content": "Now it is formatted for the message. Take that `echo` command and the part that formats it, put it in a sub shell, and set the output into a variable named `BIKE_INFO_FORMATTED`. Here's an example: `BIKE_INFO_FORMATTED=$()`", "hints": [ "You want to put the `echo $BIKE_INFO | sed 's/ |/\"/'` part in the subshell", "It should look like this: `BIKE_INFO_FORMATTED=$(echo $BIKE_INFO | sed 's/ |/\"/')`" ] } ] }, { "id": "1417", "title": "Add MAIN_MENU I have put you down for bike", "summary": "", "content": "", "steps": [ { "id": "1417.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "9b4d9968eb37457d7eb0c0e1ec9cb570ee1d2879" ] }, "content": "What you put in the subshell (`$(...)`) will be executed, and the result of it will replace the subshell. In this case, the formatted bike info was printed when you ran the script before, so the `BIKE_INFO_FORMATTED` variable will be set to that. Below the `send to main menu` comment, send users to the main menu with a message that would print `I have put you down for the 28\" Mountain Bike, Me.` if `Me` rented the 28 inch Mountain Bike.", "hints": [ "Use dynamic info for the bike info and the customer's name", "You want to use the `BIKE_INFO_FORMATTED` and `CUSTOMER_NAME` variables", "The message should look like this: `I have put you down for the $BIKE_INFO_FORMATTED Bike, $CUSTOMER_NAME.`", "Add `MAIN_MENU \"I have put you down for the $BIKE_INFO_FORMATTED Bike, $CUSTOMER_NAME.\"` below the `send to main menu` comment" ] } ] }, { "id": "1418", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1418.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "10f208d70ce19ac85701adc9b7772bc07b31ef39" ] }, "content": "Run the script and rent the next bike on the list. Use the customer with `555-5555` as their phone number. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "The customer with phone number `555-5555` and name `Me` should have at least four bikes rented" ] } ] }, { "id": "1420", "title": "echo ' M e '", "summary": "", "content": "", "steps": [ { "id": "1420.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "974f802afb1fc9ec296a3a33080ac053f62634b9" ] }, "content": "There's an extra space around the customer's name. You can use `sed` again to fix that. In the terminal, enter `echo ' M e '` to print `M e` with spaces around it to see if you can find out how.", "hints": [ "Enter the `echo ' M e '` in the terminal", "Not the psql one" ] } ] }, { "id": "1422", "title": "echo \"$(echo ' M e ').\"", "summary": "", "content": "", "steps": [ { "id": "1422.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "5131e632231387b3e950f286ecb3fbd1928e4f1b" ] }, "content": "It printed, but you can only assume there's a space at the end. Place the last command in a subshell with quotes around it. Put a period right after the subshell and echo the whole thing in the terminal. Here's how it looks: `echo \"$(echo ' M e ').\"`", "hints": [ "Enter `echo \"$(echo ' M e ').\"` in the terminal" ] } ] }, { "id": "1424", "title": "echo \"$(echo ' M e ' | sed 's/ //').\"", "summary": "", "content": "", "steps": [ { "id": "1424.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "a62dd1587899ef13ad262796ae19cbe3a53d4d7f" ] }, "content": "Now you can be certain there's a space at the end. Within the subshell of the last command, use a pipe and the `sed` command to replace the first space with no space. Here's the `sed` replacement pattern you want: `'s/ //'`.", "hints": [ "The previous command was `echo \"$(echo ' M e ').\"`", "Here's an example of how the subshell should look: `$(echo ' M e ' | sed )`", "This is the exact subshell: `$(echo ' M e ' | sed )`", "Enter `echo \"$(echo ' M e ' | sed 's/ //').\"` in the terminal" ] } ] }, { "id": "1425", "title": "echo \"$(echo ' M e ' | sed 's/ //g').\"", "summary": "", "content": "", "steps": [ { "id": "1425.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "0297e57d044f50df30dce861cb6694734268da45" ] }, "content": "That removed only the first space it found. Change the previous command to replace all instances of a space instead of just the first one.", "hints": [ "The previous command was `echo \"$(echo ' M e ' | sed 's/ //').\"`", "Use a regex flag to make the suggested modification", "You want to add the `g` flag to the `sed` replacement pattern.", "The `sed` pattern should look like this: `'s/ //g'`", "Enter `echo \"$(echo ' M e ' | sed 's/ //g').\"` in the terminal" ] } ] }, { "id": "1427", "title": "echo \"$(echo ' M e ' | sed 's/^ //g').\"", "summary": "", "content": "", "steps": [ { "id": "1427.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "16dd1ef9658de173778f7cd8bff829e1df86224e" ] }, "content": "That replaced all the spaces. You only had an extra space at the beginning of the customer name. Add a `^` in front of the space in the replacement pattern of the last command to only replace a space at the beginning of the text.", "hints": [ "The previous command was `echo \"$(echo ' M e ' | sed 's/ //g').\"`", "You want to change the matching pattern to (`^`)", "The matching pattern is between the first and second forward slashes", "The `sed` pattern should look like this: `s/^ //g`", "Enter `echo \"$(echo ' M e ' | sed 's/^ //g').\"` in the terminal" ] } ] }, { "id": "1428", "title": "echo \"$(echo ' M e ' | sed 's/^ //g').\"", "summary": "", "content": "", "steps": [ { "id": "1428.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "856933455e4391ab78028ac75ba8fa68aa803986" ] }, "content": "The caret you added means that's the start of the text. So it will replace a space only if it's at the beginning. Enter the last command, but add two more spaces (three total) at the beginning of the **text**.", "hints": [ "The previous command was `echo \"$(echo ' M e ' | sed 's/^ //g').\"`", "Change the `' M e '` part to include the suggestion", "The new text should be '   M e ' (`'M e '`)", "In the terminal, enter echo \"$(echo '   M e ' | sed 's/^ //g').\"" ] } ] }, { "id": "1430", "title": "echo \"$(echo ' M e ' | sed 's/^ *//g').\"", "summary": "", "content": "", "steps": [ { "id": "1430.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "d07845a540edd2eb81a8224a41b30220972b7029" ] }, "content": "The (`^`) pattern only replaced the first space. Add `*` at the end of the matching pattern to replace all spaces at the beginning of text.", "hints": [ "The previous command was echo \"$(echo '   M e ' | sed 's/^ //g').\"", "The matching pattern is between the first and second forward slash", "The new pattern is: `'s/^ *//g'`", "Enter echo \"$(echo '   M e ' | sed 's/^ *//g').\" in the terminal" ] } ] }, { "id": "1432", "title": "echo \"$(echo ' M e ' | sed 's/ $//g').\"", "summary": "", "content": "", "steps": [ { "id": "1432.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "47c5fdda3206c171ae207a22fce9e2a2dfb0b625" ] }, "content": "The customer name only had an extra space at the beginning. Unsure as to why, but there may be others with extra spaces at the end as well. You can match the end of text with `$`. Change the matching pattern of the last command so it replaces a single space at the end. The pattern is  $ (`$`).", "hints": [ "The previous command was echo \"$(echo '   M e ' | sed 's/^ *//g').\"", "The matching pattern is between the first and second forward slash", "Change the matching pattern to the suggestion", "Enter echo \"$(echo '   M e ' | sed 's/ $//g').\" in the terminal" ] } ] }, { "id": "1433", "title": "echo \"$(echo ' M e ' | sed 's/ $//g').\"", "summary": "", "content": "", "steps": [ { "id": "1433.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "a1257907e4ea71fc1585d24b2e92554a7b882840" ] }, "content": "Add two more spaces to the end of the **text** in the previous command (three spaces total).", "hints": [ "The previous command was echo \"$(echo '   M e ' | sed 's/ $//g').\"", "The matching pattern is between the first and second forward slash", "Change the matching pattern to the suggestion", "Enter echo \"$(echo '   M e   ' | sed 's/ $//g').\" in the terminal" ] } ] }, { "id": "1435", "title": "echo \"$(echo ' M e ' | sed 's/ *$//g').\"", "summary": "", "content": "", "steps": [ { "id": "1435.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "950f11b5eb8f58900f246d5483bc3b6369e9ad64" ] }, "content": "The pattern only replaces a single space at the end. Change the last command so it replaces all spaces at the end of the text.", "hints": [ "The previous command was echo \"$(echo '   M e   ' | sed 's/ $//g').\"", "Use `*` in a pattern after a character to replace zero or more of that character", "The matching pattern you want is  *$ (`*$`)", "Change the matching pattern to the suggestion", "Enter echo \"$(echo '   M e   ' | sed 's/ *$//g').\" in the terminal" ] } ] }, { "id": "1436", "title": "echo \"$(echo ' M e ' | sed 's/^ *| *$//g').\"", "summary": "", "content": "", "steps": [ { "id": "1436.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "5a7b5cedeed96a46a24a4ce1d81acd88a3701a7e" ] }, "content": "That replaced all the spaces at the end of the text. You can use `|` as an \"or\" operator in a matching pattern to replace one pattern or another. Use it to change the matching pattern so it would replace any amount of spaces at the beginning and any amount of spaces at the end of the text.", "hints": [ "The previous command was echo \"$(echo '   M e   ' | sed 's/ *$//g').\"", "You want to replace the ^ * (`^*`) pattern", "And the  *$ (`*$`) pattern", "The matching pattern should look like this: `'s/^ *| *$//g'`", "Enter echo \"$(echo '   M e   ' | sed 's/^ *| *$//g').\"" ] } ] }, { "id": "1437", "title": "man sed", "summary": "", "content": "", "steps": [ { "id": "1437.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "86f0b3152dc2ad6554eadaee3b9b8904b6b7f93e" ] }, "content": "That didn't work. It doesn't like that \"or\" (`|`) operator for some reason. Check the manual of the `sed` command to see if you can find anything.", "hints": [ "Here's an example of how to see a manual: `man `", "Enter `man sed` in the terminal", "Press enter until you have seen the whole manual" ] } ] }, { "id": "1438", "title": "echo \"$(echo ' M e ' | sed -r 's/^ *| *$//g').\"", "summary": "", "content": "", "steps": [ { "id": "1438.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "35f5112ae6072800e75e2a5a8ddab0a5bca70e7a" ] }, "content": "Somewhere in there is a flag for using extended regular expressions with `sed`. That might work. Add it to the echo \"$(echo '   M e   ' | sed 's/^ *| *$//g').\" command that didn't work to find out.", "hints": [ ":point_down:", "Find the flag in the terminal output for using extended regular expressions with `sed`", "It's the `-E` flag", "You previously entered echo \"$(echo '   M e   ' | sed 's/^ *| *$//g').\"", "Add the `-E` flag to the `sed` part of that command", "Enter echo \"$(echo '   M e   ' | sed -E 's/^ *| *$//g').\" in the terminal" ] } ] }, { "id": "1440", "title": "Change to trim CUSTOMER_NAME", "summary": "", "content": "", "steps": [ { "id": "1440.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "d13551b1f84f0081a32feb104d2349798a6e900a" ] }, "content": ":wink: That trimmed all spaces from the front and end of the text. Back in the last message of your script, place the `CUSTOMER_NAME` variable in a subshell, echo and pipe it into a `sed` command that removes all spaces from the front and back. Use the same method you used in the terminal.", "hints": [ "Here's an example: `$(echo $CUSTOMER_NAME | sed ...)`", "`^ *` will match all spaces at the beginning of text, and  *$ will match spaces at the end", "The previous command was echo \"$(echo '   M e   ' | sed -r 's/^ *| *$//g').\"", "Change the `$CUSTOMER_NAME` variable in the last message to `$(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')`" ] } ] }, { "id": "1442", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1442.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "17ad24e7f45287751836fb6a47d33c0ec4a6d526" ] }, "content": "Run the script and rent another bike with the customer whose phone number is `555-5555`. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "The customer with phone number `555-5555` and name `Me` should have at least five bikes rented" ] } ] }, { "id": "1444", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1444.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "2d280eb500a645862863b3d3b8c29ce3cbc7661e" ] }, "content": "Run the script again. Rent another bike, use `000-0000` as the phone number this time, and `Test` as the name to create a new customer. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "The customer with phone number `000-0000` and name `Test` should have at least one bike rented" ] } ] }, { "id": "1446", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1446.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "7ceeea7d385f949c309fe74e942b601f980d742c" ] }, "content": "Run the script again. Rent another bike with the customer you just created. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "The customer with phone number `000-0000` and name `Test` should have at least two bikes rented" ] } ] }, { "id": "1448", "title": "SELECT * FROM bikes ORDER BY bike_id", "summary": "", "content": "", "steps": [ { "id": "1448.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "4c99c42a9cccf2e27bb290ac5f7bb7dbd9844728" ] }, "content": "In the psql prompt, view all the data in your bikes table in order by the `bike_id`.", "hints": [ "Use the `SELECT`, `FROM`, and `ORDER BY` keywords with `*` to view all the data", "Enter `SELECT * FROM bikes ORDER BY bike_id;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1449", "title": "SELECT * FROM bikes ORDER BY bike_id", "summary": "", "content": "", "steps": [ { "id": "1449.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "20a2d380e30f8d03ee5a70ab3f167f764a22db68" ] }, "content": "There should be two bikes left available to rent. Next, look at all the data in the customers table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM customers;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1450", "title": "SELECT * FROM bikes ORDER BY bike_id", "summary": "", "content": "", "steps": [ { "id": "1450.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "a110691a42638c8fb020a326de03027ee7495dfc" ] }, "content": "There should two customers in that table now. Lastly, look at all the data in the rentals table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM rentals;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1453", "title": "Delete echo Return Menu", "summary": "", "content": "", "steps": [ { "id": "1453.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "b45a35eb8e3e7b9f5b817790a939e0996b3dc2cf" ] }, "content": "The rent functionality looks like it all works. Delete the `echo Return Menu` line in the `RETURN_MENU` function so you can get started with that.", "hints": [ "The `RETURN_MENU` function should be empty", "The `RETURN_MENU` function should look like this:\n```sh\nRETURN_MENU() {\n\n}\n```" ] } ] }, { "id": "1457", "title": "Add comments to RETURN_MENU", "summary": "", "content": "", "steps": [ { "id": "1457.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "4d1168f40babac9c99abdcf118e8d1f96a8c76ef" ] }, "content": "Add three single line comments to the return menu function; `get customer info`, `if not found`, and `send to main menu`, in that order.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "The comments should be in the `RETURN_MENU` function", "The `RETURN_MENU` function should look like this:\n```sh\nRETURN_MENU() {\n # get customer info\n\n # if not found\n\n # send to main menu\n\n}\n```" ] } ] }, { "id": "1460", "title": "Start the Return Bike Functionality", "summary": "", "content": "", "steps": [ { "id": "1460.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "caece3277b1b5078ec824e7b16ad25d922413626" ] }, "content": "Below the `get customer info` comment you just added, print `What's your phone number?` with a new line in front of the sentence.", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nWhat's your phone number?\"` below the suggested comment" ] } ] }, { "id": "1470", "title": "Read PHONE_NUMBER", "summary": "", "content": "", "steps": [ { "id": "1470.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "1c9c1c9f2a3fd19b114d368e3270c956e25d19af" ] }, "content": "Just below that, use `read` to get input into a `PHONE_NUMBER` variable.", "hints": [ "Here's an example: `read `", "Add `read PHONE_NUMBER` to the suggested area", "Add it below where you print `What's your phone number?`" ] } ] }, { "id": "1472", "title": "Add CUSTOMER_ID", "summary": "", "content": "", "steps": [ { "id": "1472.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "87441f6ec6ddb3898ccf8c103a37abf1302f2b56" ] }, "content": "Just below that, set the `CUSTOMER_ID` variable to a query that gets the customer ID from the database using the phone number they gave you.", "hints": [ "Here's an example: `CUSTOMER_ID=$($PSQL \"\")`", "You want to get the `customer_id` column from the customers table using the `PHONE_NUMBER` variable in your condition to get it", "The condition you want is `WHERE phone = '$PHONE_NUMBER'`", "The query looks like this: `SELECT customer_id FROM customers WHERE phone = '$PHONE_NUMBER'`", "Add `CUSTOMER_ID=$($PSQL \"SELECT customer_id FROM customers WHERE phone = '$PHONE_NUMBER'\")` below the `read PHONE_NUMBER` line in the `RETURN_MENU` function" ] } ] }, { "id": "1474", "title": "Add if -z CUSTOMER_ID", "summary": "", "content": "", "steps": [ { "id": "1474.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "dd44852953cc49723618482a8a73f90fcf314214" ] }, "content": "If they are in the database, the variable will be their `customer_id`. If not, it will be empty. Below the `if not found` comment, add an `if` statement that checks if it's empty. Put the `send to main menu` comment in the `then` area.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition you want is `-z $CUSTOMER_ID`", "Place the `# send to main menu` comment in the `` area", "The `if` condition should look like this:\n```sh\nif [[ -z $CUSTOMER_ID ]]\nthen\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1475", "title": "Add MAIN_MENU I could not find a record for that phone number", "summary": "", "content": "", "steps": [ { "id": "1475.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "50abae286ba7729dea0f22952985edae8062ab89" ] }, "content": "If the customer isn't found, send them to the main menu with the message `I could not find a record for that phone number.`", "hints": [ "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"I could not find a record for that phone number.\"` below the `send to main menu` comment" ] } ] }, { "id": "1476", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1476.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "9232f96ef9360b1a62fc88bd98591c003a3c2bdf" ] }, "content": "Run the script and go to the return menu. Enter a phone number that is not in the database. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1478", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1478.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "6e158cb4e111541bdcab1a7579dd81d94abd9789" ] }, "content": "Add an `else` to the `if` condition for if the phone number is found in the database. Place `get customer's rentals`, `if no rentals`, and `send to main menu` in the `else` area as single line comments.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "The comments should be in the `else` area of the `if [[ -z CUSTOMER_ID ]]` statement", "An `if/else` statement looks like this:\n```sh\nif [[ ]]\nthen\n \nelse\n \nfi\n```", "The `else` area should look like this:\n```sh\nelse\n # get customer's rentals\n\n # if no rentals\n\n # send to main menu\n\nfi\n```", "The whole `if` should look like this:\n```sh\nif [[ -z $CUSTOMER_ID ]]\nthen\n # send to main menu\n MAIN_MENU \"I could not find a record for that phone number.\"\nelse\n # get customer's rentals\n\n # if no rentals\n\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1480", "title": "psql SELECT * FROM bikes", "summary": "", "content": "", "steps": [ { "id": "1480.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "6a17274cc41c401c9de9fc5f59d3a7f12d18259c" ] }, "content": "You want to find out what rentals a customer has using their phone number and display them. You will need to join all the tables. Start by using the psql prompt to view all the data in the `bikes` table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM bikes;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1485", "title": "psql SELECT * FROM bikes LEFT JOIN rentals", "summary": "", "content": "", "steps": [ { "id": "1485.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "e8f0f0a1daa40e61de6a76194b6a51971d1abcfa" ] }, "content": "Next, use a `LEFT JOIN` with `bikes` as the left table to join the bikes and rentals tables. Use the `USING` keyword to join the two tables.", "hints": [ "You need the `SELECT`, `FROM`, `LEFT JOIN`, and `USING` keywords", "Here's an example: `SELECT FROM LEFT JOIN USING()`", "Enter `\\d bikes` or `\\d rentals` in the psql prompt to view the details of the table and find the foreign key column", "It's the `bike_id` column", "Enter `SELECT * FROM bikes LEFT JOIN rentals USING(bike_id);` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1490", "title": "psql SELECT bikes INNER JOIN rentals", "summary": "", "content": "", "steps": [ { "id": "1490.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "25fe5831afbb8dfa48b112201b70ac097e1aeb90" ] }, "content": "You only need the bikes that are being rented. Use an inner join with the same two tables to only get those. Use the `USING` keyword again.", "hints": [ "It's an `INNER JOIN`", "You need the `SELECT`, `FROM`, `INNER JOIN`, and `USING` keywords", "Here's an example: `SELECT FROM INNER JOIN USING()`", "Enter `SELECT * FROM bikes INNER JOIN rentals USING(bike_id);` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1500", "title": "psql SELECT bikes INNER JOIN rentals INNER JOIN customers", "summary": "", "content": "", "steps": [ { "id": "1500.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "2a1980b82478086ba788f266422073a66c662b33" ] }, "content": "Add a join to the previous command that joins the last table so you can get the customer information. Use an `INNER JOIN` and the `USING` keyword again.", "hints": [ "The previous query was `SELECT * FROM bikes INNER JOIN rentals USING(bike_id);`", "Here's an example: `SELECT FROM INNER JOIN USING() INNER JOIN USING(foreign_key)`", "Enter `\\d rentals` or `\\d customers` in the psql prompt to view the details of the table and find the foreign key column", "It's the `customer_id` column", "Enter `SELECT * FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id);` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1510", "title": "psql Add conditions to the query", "summary": "", "content": "", "steps": [ { "id": "1510.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "46fcb56160b70eb5ac305305c0b19b7735bfd06f" ] }, "content": "Add two conditions to the last query to narrow down the results to the bikes that are currently being rented by customer with `555-5555` as their phone number. The second condition should check the `date_returned` column", "hints": [ "The previous query was `SELECT * FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id);`", "You want to add a `WHERE AND ` to the last query", "Use the `IS NULL` keyword to check the `date_returned` in one of the conditions", "The two conditions are `WHERE phone = '555-5555' AND date_returned IS NULL`", "Enter `SELECT * FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND date_returned IS NULL;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1520", "title": "psql SELECT only columns", "summary": "", "content": "", "steps": [ { "id": "1520.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "6065d09fba6a3512e659efea6d57759d19009795" ] }, "content": "Now you have all the rentals for one specific customer. Only get the columns you need to display the bike information to them. They are the same three columns you used to display the list of available bikes.", "hints": [ "The previous query was `SELECT * FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND date_returned IS NULL;`", "The three columns you want are `bike_id`, `type`, and `size`", "Enter `SELECT bike_id, type, size FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND date_returned IS NULL;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1525", "title": "psql SELECT ORDER BY", "summary": "", "content": "", "steps": [ { "id": "1525.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "91ffa17ba1b83440e9d7f91526ba6217bd48dc0c" ] }, "content": "One more thing, order the results of the last query by their `bike_id` column.", "hints": [ "The previous query was `SELECT bike_id, type, size FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND date_returned IS NULL;`", "Add `ORDER BY bike_id` to the end of the last query", "Enter `SELECT bike_id, type, size FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND date_returned IS NULL ORDER BY bike_id;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1530", "title": "Add CUSTOMER_RENTALS", "summary": "", "content": "", "steps": [ { "id": "1530.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "c69d670a6567b7fc65d97f63095abcd9e51d3e12" ] }, "content": "That's the query you will need to use to get the bikes a customer is renting. In your script below the `get customer's rentals` comment. Create a `CUSTOMER_RENTALS` variable that gets the rentals for the customer. Use the `PHONE_NUMBER` variable to get them.", "hints": [ "Here's an example: `CUSTOMER_RENTALS=$($PSQL \"\")`", "You previously entered `SELECT bike_id, type, size FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND date_returned IS NULL ORDER BY bike_id;` in the psql prompt", "All the columns and tables should be in the same order as in the above query", "The query looks like this: `SELECT bike_id, type, size FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '$PHONE_NUMBER' AND date_returned IS NULL ORDER BY bike_id`", "Add `CUSTOMER_RENTALS=$($PSQL \"SELECT bike_id, type, size FROM bikes INNER JOIN rentals USING(bike_id) INNER JOIN customers USING(customer_id) WHERE phone = '$PHONE_NUMBER' AND date_returned IS NULL ORDER BY bike_id\")` below the `get customer's rentals` comment" ] } ] }, { "id": "1540", "title": "Add echo CUSTOMER_RENTALS", "summary": "", "content": "", "steps": [ { "id": "1540.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "4b3060ad36b14e7316f52e08495544a4cb711130" ] }, "content": "Below the variable you just created, use `echo` to print it. Make sure to put double quotes around it.", "hints": [ "Here's an example: `echo \"\"`", "Use the variable with `$CUSTOMER_RENTALS`", "Add `echo \"$CUSTOMER_RENTALS\"` to the suggested area" ] } ] }, { "id": "1550", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1550.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "8e6072d768a166dee0aa42d2c30384b157fa8d8f" ] }, "content": "Run the script and go to the return menu. Enter `555-5555` for the phone number to see the rentals for `Me`.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1560", "title": "Add if -z CUSTOMER_RENTALS", "summary": "", "content": "", "steps": [ { "id": "1560.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "102bb4d8762123cea9de4e8ff90bb3b22db66e82" ] }, "content": "The query is working. If the customer has no rentals, the variable will be empty. Below the `if no rentals` comment, add an `if` condition that checks if it's empty. Put the `send to main` menu comment in the `then` area again.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition you want is `-z $CUSTOMER_RENTALS`", "Place the `# send to main menu` comment in the `` area", "The `if` condition should look like this:\n```sh\nif [[ -z $CUSTOMER_RENTALS ]]\nthen\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1563", "title": "Add MAIN_MENU You do not have any bikes rented", "summary": "", "content": "", "steps": [ { "id": "1563.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "3dfd1fffe0137605522845fd1045a1c36058241f" ] }, "content": "If the customer has no rentals, send them to the main menu with the message `You do not have any bikes rented.` Add the code below the next comment.", "hints": [ "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"You do not have any bikes rented.\"` below the `send to main menu` comment" ] } ] }, { "id": "1570", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1570.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "eb9c51e58eb2d8838b9ca471de55ad4445d3ade1" ] }, "content": "Add an `else` to the condition for when the customer does have rentals. Place four single line comments in it; `display rented bikes`, `ask for bike to return`, `if not a number`, and `send to main menu`.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "The comments should be in the `else` area of the `if [[ -z CUSTOMER_RENTALS ]]` statement", "The `else` area should look like this:\n```sh\nelse\n # display rented bikes\n\n # ask for bike to return\n\n # if not a number\n\n # send to main menu\n\nfi\n```", "The whole `if` should look like this:\n```sh\nif [[ -z $CUSTOMER_RENTALS ]]\nthen\n # send to main menu\n MAIN_MENU \"You do not have any bikes rented.\"\nelse\n # display rented bikes\n\n # ask for bike to return\n\n # if not a number\n\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1572", "title": "Add echo Here are your rentals", "summary": "", "content": "", "steps": [ { "id": "1572.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "f997487a6c64797b0902a34634701ce0b8afc57e" ] }, "content": "Below the `display rented bikes` comment, print `Here are your rentals:` with a new line in front of it.", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nHere are your rentals:\"` below the suggested comment" ] } ] }, { "id": "1575", "title": "Add echo CUSTOMER_RENTALS", "summary": "", "content": "", "steps": [ { "id": "1575.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "585e7c61d4288209987819009068a06bc4c0e09c" ] }, "content": "Move the `echo $CUSTOMER_RENTALS` line to below the line you just printed.", "hints": [ "Move the suggested code below where you print `Here are your rentals:`", "You should only print the variable in that one spot", "Place the `echo \"$CUSTOMER_RENTALS\"` line in the suggested spot" ] } ] }, { "id": "1578", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1578.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "7213661a8c8e97134c1b8b1316aad5dee644dfd5" ] }, "content": "Run the script and go to the return menu. Enter `555-5555` for the phone number to see the rented bikes.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1580", "title": "Add pipe and while loop", "summary": "", "content": "", "steps": [ { "id": "1580.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "01da5277b1d053e60c421ea3db61c702fc3c7af9" ] }, "content": "Where you print the list of rented bikes, pipe the command into a `while` loop that reads the data. You should read the data into `BIKE_ID`, `BAR`, `TYPE`, `BAR`, and `SIZE` variables. Make it print each rented bike in the same fashion as the list of available bikes.", "hints": [ "Here's an example:\n```sh\necho \"$CUSTOMER_RENTALS\" | while read \ndo\n echo \ndone\n```", "The first line should look like this: `echo \"$CUSTOMER_RENTALS\" | while read BIKE_ID BAR TYPE BAR SIZE`", "The loop should print `1) 27\" Mountain Bike` for each bike with the appropriate bike info", "The whole thing looks like this:\n```sh\necho \"$CUSTOMER_RENTALS\" | while read BIKE_ID BAR TYPE BAR SIZE\ndo\n echo \"$BIKE_ID) $SIZE\\\" $TYPE Bike\"\ndone\n```" ] } ] }, { "id": "1585", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1585.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "355e27f791133d327ce33a947af17ce1ea073810" ] }, "content": "Run the script and go to the return menu. Enter the same phone number again to make sure the list is showing up correctly.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1590", "title": "Add echo Which bike would you like to return?", "summary": "", "content": "", "steps": [ { "id": "1590.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "3eceedfb25992f783ca71f6d6a48059b494429f6" ] }, "content": "Below the `ask for bike to return` comment, print `Which one would you like to return?` with a new line in front of it.", "hints": [ "Use `echo` with the `-e` flag and the new line character (`\\n`) to print the suggested message", "Use double quotes around the message", "Here's an example: `echo -e \"\\n\"`", "Add `echo -e \"\\nWhich one would you like to return?\"` below the suggested comment" ] } ] }, { "id": "1600", "title": "read BIKE_ID_TO_RETURN", "summary": "", "content": "", "steps": [ { "id": "1600.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "f959f494acc50f34f2eae217a7a248dc2e3eb6fb" ] }, "content": "Below the line you just printed, read input into a `BIKE_ID_TO_RETURN` variable.", "hints": [ "Here's an example: `read `", "Add `read BIKE_ID_TO_RETURN` to the suggested area", "Add it below where you print `Which one would you like to return?`" ] } ] }, { "id": "1602", "title": "Add if BIKE_ID_TO_RETURN not a number", "summary": "", "content": "", "steps": [ { "id": "1602.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "329b5eb5798c49d0c20d3a42446f57dc7b792c43" ] }, "content": "Below the `if not a number` comment, check if the input for the bike ID to return is a number using the same method you did earlier. Place the `send to main menu` comment in the statement.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition should check that the `$BIKE_ID_TO_RETURN` variable is not a number using the pattern matching operator (`=~`) and the pattern `^[0-9]+$`", "The condition you want is `[[ ! $BIKE_ID_TO_RETURN =~ ^[0-9]+$ ]]`", "Place the `# send to main menu` comment in the `` area", "The `if` condition should look like this:\n```sh\nif [[ ! $BIKE_ID_TO_RETURN =~ ^[0-9]+$ ]]\nthen\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1605", "title": "Add MAIN_MENU That is not a valid bike number", "summary": "", "content": "", "steps": [ { "id": "1605.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "4706bf0c59bda21bcce9ee0495f809b6feaedeeb" ] }, "content": "If they don't input a number, send them to the main menu with `That is not a valid bike number.` as the message.", "hints": [ "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"That is not a valid bike number.\"` below the `send to main menu` comment" ] } ] }, { "id": "1607", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1607.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "8128eac84a00f1c578c68bf4d014161c2f690b5f" ] }, "content": "Add an `else` for when they do input a number. Place `check if input is rented`, `if input not rented`, and `send to main menu` single line comments in it.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "The comments should be in the `else` area of the `if [[ ! $BIKE_ID_TO_RETURN =~ ^[0-9]+$ ]]` statement", "The `else` area should look like this:\n```sh\nelse\n # check if input is rented\n\n # if input not rented\n\n # send to main menu\n\nfi\n```", "The whole `if` should look like this:\n```sh\nif [[ ! $BIKE_ID_TO_RETURN =~ ^[0-9]+$ ]]\nthen\n # send to main menu\n MAIN_MENU \"That is not a valid bike number.\"\nelse\n # check if input is rented\n\n # if input not rented\n\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1610", "title": "psql SELECT rentals INNER JOIN customers", "summary": "", "content": "", "steps": [ { "id": "1610.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "f7fcfa6cfa3d6925323d782bafb84f9c7c7e2c78" ] }, "content": "You need to check if the input is a `bike_id` rented by the customer so you can return it. In the psql prompt, join the `rentals` and `customers` tables with an `INNER JOIN` using the `USING` keyword.", "hints": [ "You need the `SELECT`, `FROM`, `INNER JOIN`, and `USING` keywords", "Here's an example: `SELECT FROM INNER JOIN USING()`", "Enter `\\d rentals` or `\\d customers` in the psql prompt to view the details of the table and find the foreign key column", "It's the `customer_id` column", "Enter `SELECT * FROM rentals INNER JOIN customers USING(customer_id);` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1620", "title": "psql Add conditions to the query", "summary": "", "content": "", "steps": [ { "id": "1620.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "4c57cc6053ab9d0cbc2544f545088238b48497f1" ] }, "content": "Add three conditions to the previous query. Check the `phone`, `bike_id`, and `date_returned` columns to narrow the results to the first bike you rented with `Me`.", "hints": [ "The previous query was `SELECT * FROM rentals INNER JOIN customers USING(customer_id);`", "You want to add a `WHERE AND AND ` to the last query", "Use the `IS NULL` keyword to check the `date_returned` in one of the conditions", "The other two conditions should check the `phone` and `bike_id` of the first rental", "The three conditions are `WHERE phone = '555-5555' AND bike_id = 1 AND date_returned IS NULL`", "Enter `SELECT * FROM rentals INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND bike_id = 1 AND date_returned IS NULL;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1625", "title": "psql Only get columns needed", "summary": "", "content": "", "steps": [ { "id": "1625.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "12a640e15908c5f313168be88fcbdb07b73c28bb" ] }, "content": "You only need to know what bike is going to be returned. Narrow the columns from the last query to only get the one column you would need for returning a bike.", "hints": [ "The previous query was `SELECT * FROM rentals INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND bike_id = 1 AND date_returned IS NULL;`", "Only column you need is the `rental_id` column", "Enter `SELECT rental_id FROM rentals INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND bike_id = 1 AND date_returned IS NULL;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1630", "title": "Add RENTAL_ID", "summary": "", "content": "", "steps": [ { "id": "1630.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "a7c1f8e3576f0ae936486b17f500337e01ebc0be" ] }, "content": "Back in the script, below the `check if input is rented` comment, create a `RENTAL_ID` variable that gets the rental ID of the bike that was input.", "hints": [ "The input is the `BIKE_ID_TO_RETURN` variable", "Here's an example: `RENTAL_ID=$($PSQL \"\")`", "You previously entered `SELECT rental_id FROM rentals INNER JOIN customers USING(customer_id) WHERE phone = '555-5555' AND bike_id = 1 AND date_returned IS NULL;` in the psql prompt", "Be sure to use the same columns from the above query for the conditions with the `PHONE_NUMBER` and `BIKE_ID_TO_RETURN` variables", "Add `RENTAL_ID=$($PSQL \"SELECT rental_id FROM rentals INNER JOIN customers USING(customer_id) WHERE phone = '$PHONE_NUMBER' AND bike_id = $BIKE_ID_TO_RETURN AND date_returned IS NULL\")` below the `check if input is rented` comment" ] } ] }, { "id": "1640", "title": "Add if -z RENTAL_ID", "summary": "", "content": "", "steps": [ { "id": "1640.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "d5a9b746b987bbe7c96d06846710912f163b9426" ] }, "content": "Below the `if input not rented` comment, add an `if` that checks if the `RENTAL_ID` variable is empty. Place the `send to main menu` comment in the `then` area.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nfi\n```", "The condition you want is `-z $RENTAL_ID`", "Place the `# send to main menu` comment in the `` area", "The `if` condition should look like this:\n```sh\nif [[ -z $RENTAL_ID ]]\nthen\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1645", "title": "Add MAIN_MENU You do not have that bike rented", "summary": "", "content": "", "steps": [ { "id": "1645.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "15cb8665408ec3535352c91a315b3e50a3de719e" ] }, "content": "If the input isn't rented by the given customer, send them to the main menu with `You do not have that bike rented.` as the message.", "hints": [ "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"You do not have that bike rented.\"` below the `send to main menu` comment" ] } ] }, { "id": "1648", "title": "Add else echo Rental ID RENTAL_ID found", "summary": "", "content": "", "steps": [ { "id": "1648.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "5810f678bfc1b4cb081c030f0f9fb2c8c1fc483d" ] }, "content": "Add an `else` to the `if` condition you just added. Use `echo` to print `Rental ID $RENTAL_ID found` in it so you can see if it's all working.", "hints": [ "Here's an example:\n```sh\nif [[ ]]\nthen\n \nelse\n \nfi\n```", "Place `echo \"Rental ID $RENTAL_ID found\"` in the else area", "The `if` condition should look like this:\n```sh\nif [[ -z $RENTAL_ID ]]\nthen\n # send to main menu\n MAIN_MENU \"You do not have that bike rented.\"\nelse\n echo \"Rental ID $RENTAL_ID found\"\nfi\n```" ] } ] }, { "id": "1650", "title": "Run the script", "summary": "", "content": "", "steps": [ { "id": "1650.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "baabf796e0642c78f0cc618c64db1f6a976b57ba" ] }, "content": "Run the script and go to the return menu. Enter `555-5555` to see the rented bikes. Input a bike that isn't on the list, then go to the menu again and input a bike that is on the list.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "Make sure you are in the `project` folder first" ] } ] }, { "id": "1660", "title": "Delete echo Rental ID RENTAL_ID found", "summary": "", "content": "", "steps": [ { "id": "1660.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "16db87f89d792e662fda2b61252f5ba92ce75fa3" ] }, "content": "Looks like it works. Delete the line where you print the rental ID.", "hints": [ "Delete the `echo \"Rental ID $RENTAL_ID found\"` line" ] } ] }, { "id": "1680", "title": "Add else with comments", "summary": "", "content": "", "steps": [ { "id": "1680.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "2b1187d0f79f26dd8fc713c2aceeb4b23475c403" ] }, "content": "Add three single line comments in the `else` area; `update date_returned`, `set bike availability to true`, and `send to main menu`.", "hints": [ "Here's an example of a single line comment: `# `", "Make sure the comments are in the same order listed", "The comments should be in the `else` area of the `if [[ -z $RENTAL_ID ]]` statement", "The `else` area should look like this:\n```sh\nelse\n # update date_returned\n\n # set bike availability to true\n\n # send to main menu\n\nfi\n```", "The whole `if` should look like this:\n```sh\nif [[ -z $RENTAL_ID ]]\nthen\n # send to main menu\n MAIN_MENU \"You do not have that bike rented.\"\nelse\n # update date_returned\n\n # set bike availability to true\n\n # send to main menu\n\nfi\n```" ] } ] }, { "id": "1690", "title": "Add RETURN_BIKE_RESULT", "summary": "", "content": "", "steps": [ { "id": "1690.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "a2d6d079217670c88b1289c239bcbd5cdbc3ee35" ] }, "content": "After a person picks a bike to return and you know that it's a bike they have rented, you need to update all the info in the database to return it. Below the `update date_returned` comment, create a `RETURN_BIKE_RESULT` variable that sets the `date_returned` column to `NOW()` for the bike rented. Use the `RENTAL_ID` to figure out which row to update.", "hints": [ "Here's an example: `RETURN_BIKE_RESULT=$($PSQL \"\")`", "You want to use the `UPDATE`, `SET`, `NOW()`, and `WHERE` keywords in the query", "Here's an example of the query: `UPDATE
SET = WHERE `", "The query you want is `UPDATE rentals SET date_returned = NOW() WHERE rental_id = $RENTAL_ID`", "Add `RETURN_BIKE_RESULT=$($PSQL \"UPDATE rentals SET date_returned = NOW() WHERE rental_id = $RENTAL_ID\")` below the `update date_returned` comment" ] } ] }, { "id": "1710", "title": "Add SET_TO_TRUE_RESULT", "summary": "", "content": "", "steps": [ { "id": "1710.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "b9b91dcf9c82721387fa7d25dd88812308e3dc98" ] }, "content": "That should update the rentals table. Lastly, you need to make the bike available again. Below the `set bike availability to true` comment, create a `SET_TO_TRUE_RESULT` variable that makes the bike available again.", "hints": [ "Here's an example: `SET_TO_TRUE_RESULT=$($PSQL \"\")`", "You want to use the `UPDATE`, `SET`, and `WHERE` keywords in the query", "You want to update the `available` column to `true` for the bike with `BIKE_ID_TO_RETURN`", "The query you want is `UPDATE bikes SET available = true WHERE bike_id = $BIKE_ID_TO_RETURN`", "Add `SET_TO_TRUE_RESULT=$($PSQL \"UPDATE bikes SET available = true WHERE bike_id = $BIKE_ID_TO_RETURN\")` below the `set bike availability to true` comment" ] } ] }, { "id": "1730", "title": "Add MAIN_MENU Thank you for returning your bike", "summary": "", "content": "", "steps": [ { "id": "1730.1", "setup": { "watchers": [ "./bike-shop.sh" ], "commits": [ "456f33e4096f628f55adcf80ef30d2a9ec4d2f70" ] }, "content": "After all that is done, send them to the main menu with `Thank you for returning your bike.` as the message.", "hints": [ "Add the code below the last `send to main menu` comment", "You want to call the `MAIN_MENU` function with the message as an argument", "Here's an example: `MAIN_MENU \"\"`", "Add `MAIN_MENU \"Thank you for returning your bike.\"` below the `send to main menu` comment" ] } ] }, { "id": "1740", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1740.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "cba6cdeb24ec8e173fc35481088a90bd10385c37" ] }, "content": "Run the script and return one of the bikes that `Me` has rented out. When you are done, exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "The customer with phone number `555-5555` and name `Me` should have at least one rental with the `date_returned` column not null" ] } ] }, { "id": "1750", "title": "psql SELECT * FROM rentals", "summary": "", "content": "", "steps": [ { "id": "1750.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "eba07eb3299f62c7b8103716bfd93fafeeafa86a" ] }, "content": "In the psql prompt, view all the data in the `rentals` table.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM rentals;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1760", "title": "psql SELECT * FROM bikes ORDER BY bike_id", "summary": "", "content": "", "steps": [ { "id": "1760.1", "setup": { "watchers": [ "../queryResults.log" ], "commits": [ "aa9daf760123f970de7091d6587b0470fc528dcd" ] }, "content": "Now the rental has been returned. View all the data in the bikes table in order by their `bike_id`.", "hints": [ "Use the `SELECT` and `FROM` keywords with `*` to view all the data", "Enter `SELECT * FROM bikes ORDER BY bike_id;` in the psql prompt", "You can type `psql --username=freecodecamp --dbname=bikes` into the terminal to log in to psql if you aren't logged in." ] } ] }, { "id": "1770", "title": "./bike-shop.sh", "summary": "", "content": "", "steps": [ { "id": "1770.1", "setup": { "watchers": [ "../.bash_history" ], "commits": [ "0bb5520381d1a1769c7dea31951f2afe6c888bc3" ] }, "content": "And the bike is available again. This is the last step. Run the script once more. Feel free to play around, rent and return some bikes. When you are ready to be done, return all the bikes you rented and exit the program.", "hints": [ "Enter `./bike-shop.sh` in the terminal and press enter", "All rentals should have a `date_returned` value, and all bikes should have `available` set to `true`" ] } ] } ] }