Skip to content

Instantly share code, notes, and snippets.

@ndhoule
Created January 30, 2015 20:25
Show Gist options
  • Save ndhoule/199e746a90050c896053 to your computer and use it in GitHub Desktop.
Save ndhoule/199e746a90050c896053 to your computer and use it in GitHub Desktop.
Are you flawless? Take the quiz to find out!
#!/usr/bin/env bash
#
# Copyright 2015, Nathan Houle. Licensed under the MIT license.
#
# Bash clone of git@github.com:gilhooley/flawless.git.
#
#
# Terminal color shortcuts.
#
BOLD=$(tput bold)
LIGHT_GREEN="\033[0;32m"
LIGHT_RED="\033[0;31m"
RESET="\033[0;00m"
#
# Constants.
#
VOICE=vicki
QUESTIONS=("These diamonds" "My diamonds" "This rock" "My rock")
EXPECTED="flawless"
HOMEWORK_LINK="https://www.youtube.com/watch?v=17hPCHLMpyM"
#
# Print startup banner.
#
function print_banner() {
echo -e "================="
echo -e "= FLAWLESS QUIZ ="
echo -e "================="
echo -e ""
sleep 1
echo -e "Please answer the following questions to the best of your abilities."
sleep 2
echo -e "To quit at any time, press CTRL-C."
sleep 2
echo -e ""
}
#
# Prompt the user with the quiz.
#
# Exit 0 if the user passed, otherwise 1
#
function run_quiz() {
local passed=0
for question in "${QUESTIONS[@]}"; do
echo -ne "${LIGHT_GREEN}(Q) ${question}? ${RESET}"
read answer
if [[ $(echo $answer | awk '{print tolower($0)}') != "$EXPECTED" ]]; then
passed=1
fi
done
return "$passed"
}
#
# Output results of quiz to user.
#
function speak_results() {
if [[ $1 == 0 ]]; then
say -v $VOICE "I woke up like this, I woke up like this"
echo -e "${LIGHT_GREEN}You've passed the quiz!${RESET}"
else
say -v "${VOICE}" "Bow down bitches"
echo -e "${LIGHT_RED}You did not pass the quiz. Please study and re-take the quiz.${RESET}"
echo -e "${LIGHT_RED}Opening your homework...${RESET}"
sleep 1
open "${HOMEWORK_LINK}"
fi
}
#
# Main loop.
#
function main() {
print_banner
run_quiz
speak_results $?
}
#
# Run `main`.
#
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment