Build a Periodic Table Database

ive been stuck in this project for like 6 hours. these are the tasks that i cant do

  • If you run ./element.sh 1, ./element.sh H, or ./element.sh Hydrogen, it should output only The element with atomic number 1 is Hydrogen (H). It's a nonmetal, with a mass of 1.008 amu. Hydrogen has a melting point of -259.1 celsius and a boiling point of -252.9 celsius.

  • If you run ./element.sh script with another element as input, you should get the same output but with information associated with the given element.

  • i did them and it showed me a right output but it doesnt make it at done. so i think its a problem with my code.

  • this is my element.sh code

  • #!/bin/bash

    PSQL=“psql --username=freecodecamp --dbname=periodic_table -t --tuples-only -c”

    # no argument provided

    if [[ -z $1 ]]

    then

    echo “Please provide an element as an argument.”

    exit

    fi

    # determine if input is atomic_number or string

    if [[ $1 =~ ^[0-9]+$ ]]

    then

    ELEMENT=$($PSQL “SELECT e.atomic_number, e.name, e.symbol, t.type, p.atomic_mass, p.melting_point_celsius, p.boiling_point_celsius FROM elements e JOIN properties p USING(atomic_number) JOIN types t USING(type_id) WHERE e.atomic_number=$1;”)

    else

    ELEMENT=$($PSQL “SELECT e.atomic_number, e.name, e.symbol, t.type, p.atomic_mass, p.melting_point_celsius, p.boiling_point_celsius FROM elements e JOIN properties p USING(atomic_number) JOIN types t USING(type_id) WHERE e.name=‘$1’ OR e.symbol=‘$1’;”)

    fi

    # element not found

    if [[ -z $ELEMENT ]]

    then

    echo “I could not find that element in the database.”

    exit

    fi

    # print formatted output

    echo $ELEMENT | while read ATOMIC_NUMBER NAME SYMBOL TYPE MASS MELT BP

    do

    echo “The element with atomic number $ATOMIC_NUMBER is $NAME ($SYMBOL). It’s a $TYPE, with a mass of $MASS amu. $NAME has a melting point of $MELT celsius and a boiling point of $BP celsius.”

    done

  • anyone mind giving me the right code? im just drained from this

As a mod I have to let you know, no one is allowed to give the answer in this forum, and because you asked for it, your certificate might be in jeopardy if it is deemed you cheated on a certification project.

run these, what’s your output?

hey man, sorry for not replying but i finished the code. It appeared to be a glitch in the code. Thanks man

sorry. I never cheat I just needed help with the code. I’m done now

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