summaryrefslogtreecommitdiff
path: root/Blog/Components/Pages
diff options
context:
space:
mode:
Diffstat (limited to 'Blog/Components/Pages')
-rw-r--r--Blog/Components/Pages/Generator.razor12
-rw-r--r--Blog/Components/Pages/Generator.razor.js47
2 files changed, 59 insertions, 0 deletions
diff --git a/Blog/Components/Pages/Generator.razor b/Blog/Components/Pages/Generator.razor
new file mode 100644
index 0000000..52d9d1a
--- /dev/null
+++ b/Blog/Components/Pages/Generator.razor
@@ -0,0 +1,12 @@
1@page "/Generator"
2<PageTitle>Number generator</PageTitle>
3<PageScript Src="./Components/Pages/Generator.razor.js"></PageScript>
4
5<main>
6 <button id="bsn">Generate BSN</button>
7 <!-- <button id="iban">Generate IBAN</button> -->
8
9 <div>
10 <div id="log"></div>
11 </div>
12</main> \ No newline at end of file
diff --git a/Blog/Components/Pages/Generator.razor.js b/Blog/Components/Pages/Generator.razor.js
new file mode 100644
index 0000000..65036cd
--- /dev/null
+++ b/Blog/Components/Pages/Generator.razor.js
@@ -0,0 +1,47 @@
1import { addClass /*writeInfo*/, div, getById, span } from "/common.module.js";
2
3function writeInfo(label, msg) {
4 log.appendChild(
5 div(
6 addClass(div(addClass(span(label), "noselect"), span(msg)), "info"),
7 ),
8 );
9}
10
11export function onLoad() {
12 const gen_bsn = getById("bsn");
13 gen_bsn.addEventListener("click", generateBsn);
14}
15
16function generateBsn() {
17 const nr9 = Math.floor(Math.random() * 7);
18 const nr8 = Math.floor(Math.random() * 10);
19 const nr7 = Math.floor(Math.random() * 10);
20 const nr6 = Math.floor(Math.random() * 10);
21 const nr5 = Math.floor(Math.random() * 10);
22 const nr4 = Math.floor(Math.random() * 10);
23 const nr3 = Math.floor(Math.random() * 10);
24 let nr2 = Math.floor(Math.random() * 10);
25 const bsnNumber =
26 9 * nr9 +
27 8 * nr8 +
28 7 * nr7 +
29 6 * nr6 +
30 5 * nr5 +
31 4 * nr4 +
32 3 * nr3 +
33 2 * nr2;
34 let nr1 = Math.floor(bsnNumber - Math.floor(bsnNumber / 11) * 11);
35 if (nr1 > 9) {
36 if (nr2 > 0) {
37 nr2 -= 1;
38 nr1 = 8;
39 } else {
40 nr2 += 1;
41 nr1 = 1;
42 }
43 }
44
45 const BSNString = "" + nr9 + nr8 + nr7 + nr6 + nr5 + nr4 + nr3 + nr2 + nr1;
46 writeInfo("BSN: ", BSNString);
47}