Periodic Table Database Steps 18, 19, 27, 30

Hello everybody,
I have almost completed the Periodic Table Database, but I still have these tasks:

  • Your repository should have a main branch with all your commits

  • Your periodic_table repo should have at least five commits

  • The rest of the commit messages should start with fix:, feat:, refactor:, chore:, or test:

  • You should finish your project while on the main branch. Your working tree should be clean and you should not have any uncommitted changes
    Please tell me what I’m doing wrong.
    element.sh:

#!/bin/bash

PSQL="psql --username=freecodecamp --dbname=periodic_table -t --no-align -c"

if [[ -z $1 ]]
then
  echo "Please provide an element as an argument."
else
  if [[ $1 =~ ^[0-9]+$ ]]
  then
    ELEMENT=$($PSQL "SELECT * FROM elements INNER JOIN properties USING(atomic_number) INNER JOIN types USING(type_id) WHERE atomic_number=$1")
  else
    ELEMENT=$($PSQL "SELECT * FROM elements INNER JOIN properties USING(atomic_number) INNER JOIN types USING(type_id) WHERE symbol='$1' OR name='$1'")
  fi

  if [[ -z $ELEMENT ]]
  then
    echo "I could not find that element in the database."
  else
    echo $ELEMENT | while IFS="|" read TYPE_ID ATOMIC_NUMBER SYMBOL NAME ATOMIC_MASS MELTING_POINT BOILING_POINT TYPE
    do
      echo "The element with atomic number $ATOMIC_NUMBER is $NAME ($SYMBOL). It's a $TYPE, with a mass of $ATOMIC_MASS amu. $NAME has a melting point of $MELTING_POINT celsius and a boiling point of $BOILING_POINT celsius."
    done
  fi
fi

This is one of my first times working on this, tell me if I’m doing something wrong please and thank you.

the failing tests are not about your code, but about your use of git
what’s your current branch? do you have commits?

Yes, I do have commits. My current branch was master by accident, but I renamed it to main, which solved step 18 and then I worked a little longer and got 27 and 30 as well.
EDIT: Here is what it looks like when I type git log --oneline: 7128137 (HEAD -> main) feat: Add element search functionality
6960583 Initial commit
EDIT: What does this mean?

that you have only one commit and the name is Initial commit
you should have at least five commits

Okay, I’ll work on that right now.

After a bit of tweaking, I accidentally got myself another problem,

  • The rest of the commit messages should start with fix:, feat:, refactor:, chore:, or test:.
    Here’s the code I put in that got the error:
echo "# Periodic Table Database" > README.md
git add README.md
git commit -m "docs: Add README file"

git add element.sh
git commit -m "docs: Add comments to element.sh"

echo "*.log" > .gitignore
git add .gitignore
git log --oneline | wc -l .gitignore file"

How can I fix both this problem and the other problem?

google how to change a commit message

Actually, while you were gone, I did a bit more tweaking, and I accidentally got myself problem 30 again. Here’s my code for element.sh:

 #!/bin/bash

PSQL="psql --username=freecodecamp --dbname=periodic_table -t --no-align -c"

if [[ -z $1 ]]
then
  echo "Please provide an element as an argument."
else
  if [[ $1 =~ ^[0-9]+$ ]]
  then
    ELEMENT=$($PSQL "SELECT * FROM elements INNER JOIN properties USING(atomic_number) INNER JOIN types USING(type_id) WHERE atomic_number=$1")
  else
    ELEMENT=$($PSQL "SELECT * FROM elements INNER JOIN properties USING(atomic_number) INNER JOIN types USING(type_id) WHERE symbol='$1' OR name='$1'")
  fi

  if [[ -z $ELEMENT ]]
  then
    echo "I could not find that element in the database."
  else
    echo $ELEMENT | while IFS="|" read TYPE_ID ATOMIC_NUMBER SYMBOL NAME ATOMIC_MASS MELTING_POINT BOILING_POINT TYPE
    do
      echo "The element with atomic number $ATOMIC_NUMBER is $NAME ($SYMBOL). It's a $TYPE, with a mass of $ATOMIC_MASS amu. $NAME has a melting point of $MELTING_POINT celsius and a boiling point of $BOILING_POINT celsius."
    done
  fi
fi

and here’s my problems:

  • Your periodic_table repo should have at least five commits
  • The rest of the commit messages should start with fix:, feat:, refactor:, chore:, or test:
  • You should finish your project while on the main branch. Your working tree should be clean and you should not have any uncommitted changes
    Here is my “git log --oneline”:
    6960583 (HEAD) Initial commit
    And finally, here is my “git status”:
interactive rebase in progress; onto 6960583
Last command done (1 command done):
   pick 8cacba4 fix: Add TODO for error handling
Next commands to do (4 remaining commands):
   pick d627024 chore: Add README file
   drop 3b529f2 docs: Add README file
  (use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'main' on '6960583'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both modified:   element.sh

I’ve been working on these for a while now, and I’m quite stumped. What do I do?

Okay, I’ve solved almost every problem but this one:

  • The rest of the commit messages should start with fix:, feat:, refactor:, chore:, or test:
    Is there any way I can approach this issue without creating more issues?

I accidentally closed it, and I lost everything.

go to your gitpod dashboard you will find the workspace there

Good morning @ILM, today I started working a little bit more after I got my progress back and I was able to fix every issue except for the
“The rest of the commit messages should start with fix:, feat:, refactor:, chore:, or test:
issue and the
“You should finish your project while on the main branch. Your working tree should be clean and you should not have any uncommitted changes”
issue. I also got another issue: “If you run ./element.sh, it should output only Please provide an element as an argument. and finish running.” Thank you for your help so far :smile:
element.sh:

#!/bin/bash

PSQL="psql --username=freecodecamp --dbname=periodic_table -t --no-align -c"

if [[ -z $1 ]]
then
  echo "Please provide an element as an argument."
else
  if [[ $1 =~ ^[0-9]+$ ]]
  then
    ELEMENT=$($PSQL "SELECT * FROM elements INNER JOIN properties USING(atomic_number) INNER JOIN types USING(type_id) WHERE atomic_number=$1")
  else
    ELEMENT=$($PSQL "SELECT * FROM elements INNER JOIN properties USING(atomic_number) INNER JOIN types USING(type_id) WHERE symbol='$1' OR name='$1'")
  fi

  if [[ -z $ELEMENT ]]
  then
    echo "I could not find that element in the database."
  else
    echo $ELEMENT | while IFS="|" read TYPE_ID ATOMIC_NUMBER SYMBOL NAME ATOMIC_MASS MELTING_POINT BOILING_POINT TYPE
    do
      echo "The element with atomic number $ATOMIC_NUMBER is $NAME ($SYMBOL). It's a $TYPE, with a mass of $ATOMIC_MASS amu. $NAME has a melting point of $MELTING_POINT celsius and a boiling point of $BOILING_POINT celsius."
    done
  fi
fi
# TODO: Add more elements
if [[ $# -eq 0 ]]; then
  echo 'Error: Please provide an element as an argument'
  exit 1
fi

git log --oneline:

c8c9a10 (HEAD -> main) refactor: Add shebang to element.sh
198f588 fix: Add input validation to element.sh
30f584c chore: Add .gitignore file
fae0f0e docs: Add usage section to README
ca1dd50 feat: Add TODO for expanding element database
6f7f600 Initial commit

git-rebase-todo:

pick ca1dd50 feat: Add TODO for expanding element database
reword fae0f0e docs: Add usage section to README
pick 30f584c chore: Add .gitignore file
pick 198f588 fix: Add input validation to element.sh
pick c8c9a10 refactor: Add shebang to element.sh

git status:

On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   element.sh

no changes added to commit (use "git add" and/or "git commit -a")

\d elements:

Table "public.elements"
    Column     |         Type          | Collation | Nullable | Default 
---------------+-----------------------+-----------+----------+---------
 atomic_number | integer               |           | not null | 
 symbol        | character varying(2)  |           | not null | 
 name          | character varying(40) |           | not null | 
Indexes:
    "elements_pkey" PRIMARY KEY, btree (atomic_n
umber)
    "elements_atomic_number_key" UNIQUE CONSTRAI
NT, btree (atomic_number)
    "unique_name" UNIQUE CONSTRAINT, btree (name
)
    "unique_symbol" UNIQUE CONSTRAINT, btree (sy
mbol)
Referenced by:
    TABLE "properties" CONSTRAINT "properties_at
omic_number_fkey" FOREIGN KEY (atomic_number) RE
FERENCES elements(atomic_number)

\d properties:

Table "public.properties"
        Column         |  Type   | Collation | N
ullable | Default 
-----------------------+---------+-----------+--
--------+---------
 atomic_number         | integer |           | n
ot null | 
 atomic_mass           | numeric |           | n
ot null | 
 melting_point_celsius | numeric |           | n
ot null | 
 boiling_point_celsius | numeric |           | n

All selected from elements:

atomic_number | symbol |   name    
---------------+--------+-----------
             1 | H      | Hydrogen
             2 | He     | Helium
             3 | Li     | Lithium
             4 | Be     | Beryllium
             5 | B      | Boron
             6 | C      | Carbon
             7 | N      | Nitrogen
             8 | O      | Oxygen
             9 | F      | Fluorine
            10 | Ne     | Neon

All selected from properties:

atomic_number | atomic_mass | melting_point_cel
sius | boiling_point_celsius | type_id 
---------------+-------------+------------------
-----+-----------------------+---------
             1 |       1.008 |                -2
59.1 |                -252.9 |       2
             2 |      4.0026 |                -2
72.2 |                  -269 |       2
             3 |        6.94 |                18
0.54 |                  1342 |       1
             4 |      9.0122 |                  
1287 |                  2470 |       1
             6 |      12.011 |                  
3550 |                  4027 |       2
             7 |      14.007 |                -2
10.1 |                -195.8 |       2
             8 |      15.999 |                  
-218 |                  -183 |       2
             9 |      18.998 |                  
-220 |                -188.1 |       2
            10 |       20.18 |                -2
48.6 |                -246.1 |       2

I’m getting close, I can feel it!

for the first one please read the commit messages and read the test, and change the commit messages that are not matching.

second one, are you still on main branch? do you have uncommitted changes? (like changes to element.sh)

wasnt the last one passing earlier? you changed something, maybe element.sh?

I solved the first and the last one right now, its the second one that I’m having trouble with. For some reason, it won’t let me pass it without other unpassing, and vice versa. It’s frustrating.
EDIT: I meant I solved the second and last one my bad.

I fixed it after a long time of tweaking. Thank you for your help, I really appreciated it! :grin:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.