Created
December 9, 2022 08:29
-
-
Save rpearce/292bc9404bd443753eadfa71ffa9a24f to your computer and use it in GitHub Desktop.
Xmas present for a great brother in-law
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
set -o errtrace | |
set -o nounset | |
set -eou pipefail | |
# ============================================================================== | |
function clearscreen { | |
printf '\033c' | |
} | |
# ============================================================================== | |
function print_welcome { | |
cat <<EOF | |
--------------------------- | |
| | | |
| Welcome to | | |
| | | |
| Sam's | | |
| | | |
| Birthday Challenge! | | |
| | | |
--------------------------- | |
EOF | |
} | |
function print_overview { | |
cat <<EOF | |
----------------------------- | |
| | | |
| You will be given | | |
| | | |
| THREE | | |
| | | |
| questions about | | |
| | | |
| JS & HTML | | |
| | | |
| that you must answer | | |
| | | |
| to unlock... | | |
| | | |
----------------------------- | |
EOF | |
} | |
function print_gift_preview { | |
echo " ___ ___ ___ ___ "; | |
echo " ___ /__/\ / /\ / /\ ___ / /\ ___ "; | |
echo " / /\ \ \:\ / /:/_ / /:/_ / /\ / /:/_ / /\ "; | |
echo " / /:/ \__\:\ / /:/ /\ / /:/ /\ / /:/ / /:/ /\ / /:/ "; | |
echo " / /:/ ___ / /::\ / /:/ /:/_ / /:/_/::\ /__/::\ / /:/ /:/ / /:/ "; | |
echo " / /::\ /__/\ /:/\:\ /__/:/ /:/ /\ /__/:/__\/\:\ \__\/\:\__ /__/:/ /:/ / /::\ "; | |
echo " /__/:/\:\ \ \:\/:/__\/ \ \:\/:/ /:/ \ \:\ /~~/:/ \ \:\/\ \ \:\/:/ /__/:/\:\ "; | |
echo " \__\/ \:\ \ \::/ \ \::/ /:/ \ \:\ /:/ \__\::/ \ \::/ \__\/ \:\ "; | |
echo " \ \:\ \ \:\ \ \:\/:/ \ \:\/:/ /__/:/ \ \:\ \ \:\\"; | |
echo " \__\/ \ \:\ \ \::/ \ \::/ \__\/ \ \:\ \__\/"; | |
echo " \__\/ \__\/ \__\/ \__\/ "; | |
} | |
# ============================================================================== | |
function run_q1 { | |
local msg="${1-}" | |
clearscreen | |
print_q1 | |
if [ -n "$msg" ]; then | |
echo "$msg" | |
fi | |
read -erp "> " answer | |
if [ "$answer" = "\"Hello, Sam!\"" ] || [ "$answer" = "Hello, Sam!" ]; then | |
echo "" | |
print_q1_success | |
else | |
run_q1 "(Please try again)" | |
fi | |
} | |
function print_q1 { | |
cat <<EOF | |
-------------------------------------------- | |
| | | |
| Q1: What does the following return? | | |
| | | |
| function greet(name) { | | |
| return \`Hello, \${name}!\` | | |
| } | | |
| | | |
| greet('Sam') // ??? | | |
| | | |
-------------------------------------------- | |
EOF | |
} | |
function print_q1_success { | |
cat <<EOF | |
------------------ | |
| | | |
| Great Job! | | |
| | | |
------------------ | |
EOF | |
read -erp "(Press return to continue)" _ | |
} | |
# ============================================================================== | |
function run_q2 { | |
local msg="${1-}" | |
clearscreen | |
print_q2 | |
if [ -n "$msg" ]; then | |
echo "$msg" | |
fi | |
read -erp "> " answer | |
if [ "$answer" = "<p>This is a <em>very</em> fun quiz!</p>" ]; then | |
echo "" | |
print_q2_success | |
else | |
run_q2 "(Please try again)" | |
fi | |
} | |
function print_q2 { | |
cat <<EOF | |
---------------------------------------------- | |
| | | |
| Q2: How do you write an HTML paragraph | | |
| with the text below where the word | | |
| "very" is emphasized? | | |
| | | |
| "This is a very fun quiz!" | | |
| | | |
---------------------------------------------- | |
EOF | |
} | |
function print_q2_success { | |
cat <<EOF | |
---------------------- | |
| | | |
| Wow! You rock! | | |
| | | |
---------------------- | |
EOF | |
read -erp "(Press return to continue)" _ | |
} | |
# ============================================================================== | |
function run_q3 { | |
local msg="${1-}" | |
clearscreen | |
print_q3 | |
if [ -n "$msg" ]; then | |
echo "$msg" | |
fi | |
read -erp "> " answer | |
if [ "$answer" = "Na Na Na Na Na Na Na Na Na Na Na Na Na Na Na Na Batman!" ] || [ "$answer" = "\"Na Na Na Na Na Na Na Na Na Na Na Na Na Na Na Na Batman!\"" ]; then | |
echo "" | |
print_q3_success | |
else | |
run_q3 "(Please try again)" | |
fi | |
} | |
function print_q3 { | |
cat <<EOF | |
-------------------------------------------- | |
| | | |
| Q3: What does the following return? | | |
| (hint: type the code into the JS | | |
| web console in your browser) | | |
| | | |
| function secretMsg() { | | |
| let msg = [] | | |
| | | |
| for (let i = 0; i < 16; i++) { | | |
| msg.push("Na") | | |
| } | | |
| | | |
| msg.push("Batman!") | | |
| | | |
| return msg.join(" ") | | |
| } | | |
| | | |
| secretMsg() // ??? | | |
| | | |
-------------------------------------------- | |
EOF | |
} | |
function print_q3_success { | |
cat <<EOF | |
------------------------ | |
| | | |
| Amazing! I'm so | | |
| | | |
| proud of you! | | |
| | | |
------------------------ | |
EOF | |
read -erp "(Press return to continue)" _ | |
} | |
# ============================================================================== | |
function print_gift { | |
cat <<EOF | |
---------------------------------------------------------- | |
| | | |
| You have earned \$100 towards educational material | | |
| | | |
| to further whatever studies you are interested in, | | |
| | | |
| or you can take its value in cash right now. | | |
| | | |
| | | |
| | | |
| The choice is yours. | | |
| | | |
| | | |
| | | |
| Merry Christmas! | | |
| | | |
| ██████╗ ██████╗ ██████╗ ███████╗██████╗ ████████╗ | | |
| ██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗╚══██╔══╝ | | |
| ██████╔╝██║ ██║██████╔╝█████╗ ██████╔╝ ██║ | | |
| ██╔══██╗██║ ██║██╔══██╗██╔══╝ ██╔══██╗ ██║ | | |
| ██║ ██║╚██████╔╝██████╔╝███████╗██║ ██║ ██║ | | |
| ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ | | |
| | | |
| | | |
---------------------------------------------------------- | |
EOF | |
} | |
# ============================================================================== | |
function main { | |
clearscreen | |
print_welcome | |
read -erp "(Press return to continue)" _ | |
clearscreen | |
print_overview | |
read -erp "(Press return to continue)" _ | |
print_gift_preview | |
read -erp "(Press return to be tested)" _ | |
run_q1 | |
run_q2 | |
run_q3 | |
clearscreen | |
print_gift | |
read -erp "(Press return to go to the free exercism.org)" _ | |
open https://exercism.org | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's how to run this!
Terminal.app
application on your Mac and make it full screen (holdcommand
&option
and click the green button in the top left)