summaryrefslogtreecommitdiff
path: root/HintButton.js
diff options
context:
space:
mode:
Diffstat (limited to 'HintButton.js')
-rw-r--r--HintButton.js37
1 files changed, 37 insertions, 0 deletions
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<answer.length; i++)
+ hint += 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,
+ }
+ );
+}