From ad2e991545f37f3659f40d30c709133b4055bb9e Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 13 Apr 2021 12:33:23 -0500 Subject: create hint button --- HintButton.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 HintButton.js (limited to 'HintButton.js') diff --git a/HintButton.js b/HintButton.js new file mode 100644 index 0000000..4e081fc --- /dev/null +++ b/HintButton.js @@ -0,0 +1,37 @@ +function getHint(answer, level) +{ + const defaultText = 'Reveal Hint'; + + if (level === 0) + return defaultText; + + if (level > 3 || level >= answer.length) + return answer; + + let hint = ''; + for (let i=0; i= level ? '*' : answer[i]; + + // pad so that button size doesn't change + while (hint.length < defaultText.length) + hint = ` ${hint} `; + + return hint; +} + + +function HintButton({ answer, hintLevel, handleClick }) +{ + const hint = getHint(answer, hintLevel); + + return h( + StyleButton, + { text: hint, + style: { + 'min-width': '100px', + }, + enabled: true, + handleClick, + } + ); +} -- cgit v1.2.1