I tend to dislike my code. It’s always a mess. I can’t critique my own code tough, because I just turn it into another mess. I’ve been programming slightly better every year, but this year it hasn’t hardly changed.
#!/bin/bash RED='\e[101m' NC='3[0m' # No Color lesson[1]="#!/bin/bash" lesson[2]="#!/bin/bash" lessons=$ {#lesson[@]} current_lesson=1 speed=70 function start() { SECONDS=0 #restart timer reset_user_input string_to_type=$ {lesson[$ 1]}; length_of_string=$ {#string_to_type} echo $ string_to_type count=0 while [ "$ count" -ne "$ length_of_string" ]; do checkCharacter done time_it_took=$ SECONDS sec=60 wpm=$ ((sec / time_it_took)) wpm=$ ((wpm * length_of_string / 5)) echo " " echo "speed: "$ wpm } function checkCharacter() { IFS= read -r -s -n 1 user_input_char add_user_input $ user_input_char if [ "$ user_input_char" == " " ]; then add_user_input " " if [ "$ user_input_char" == "$ {string_to_type:$ count:1}" ]; then printf " " else printf $ {RED}" "$ {NC} fi else if [ "$ user_input_char" == "$ {string_to_type:$ count:1}" ]; then printf $ user_input_char else printf $ {RED}$ user_input_char$ {NC} fi fi let count+=1 } function check_correct() { if [ "$ user_input" == "$ string_to_type" ]; then return; else echo "too many mistakes, try again!" false; fi } function check_speed() { if [ "$ wpm" -gt speed ]; then return; else echo "too slow, try again!" false fi } function start_lesson() { start $ 1 if check_speed && check_correct; then echo "you succeeded!" echo " " # padding for every lesson return; fi echo " " # padding for every lesson false } function reset_user_input() { user_input="" } function add_user_input() { user_input=$ {user_input}$ 1 } while [ "$ current_lesson" -le "$ lessons" ]; do echo "lesson:" $ current_lesson until start_lesson $ current_lesson; do : ; done; let current_lesson+=1 done