summaryrefslogtreecommitdiff
path: root/HintButton.js
blob: 4e081fc1971183552c49bd0bb7fef361bb5e4dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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,
      }
   );
}