|
7 | 7 | let Vectors: Vector[] = []; |
8 | 8 |
|
9 | 9 | // Initialize with preset Values |
10 | | - Vectors.push(new Vector(1, 2, 3)); |
11 | | - Vectors.push(new Vector(4, 5, 6)); |
| 10 | + let InitVectors: Vector[] = [new Vector(1, 2, 3), new Vector(4, 5, 6)]; |
| 11 | +
|
| 12 | + function Initialize() { |
| 13 | + Vectors = []; |
| 14 | + InitVectors.map((v: Vector) => Vectors.push(v)); |
| 15 | + } |
12 | 16 |
|
13 | 17 | let input_i: number, input_j: number, input_k: number; |
14 | 18 |
|
15 | 19 | function addVectorFromInput(): void { |
16 | | - if (input_i == null || input_j == null || input_k == null) { |
17 | | - console.log("ERROR addVectorFromInput(): Input Invalid"); |
18 | | - return; |
19 | | - } |
20 | | -
|
21 | | - Vectors = [...Vectors, new Vector(input_i, input_j, input_k)]; |
| 20 | + Vectors = [ |
| 21 | + ...Vectors, |
| 22 | + new Vector(input_i ?? 0, input_j ?? 0, input_k ?? 0), |
| 23 | + ]; |
22 | 24 | [input_i, input_j, input_k] = [null, null, null]; |
23 | 25 | } |
| 26 | +
|
| 27 | + Initialize(); |
24 | 28 | </script> |
25 | 29 |
|
26 | 30 | <body id="MainBody"> |
|
36 | 40 | <input type="number" placeholder="i" bind:value={input_i} /> |
37 | 41 | <input type="number" placeholder="j" bind:value={input_j} /> |
38 | 42 | <input type="number" placeholder="k" bind:value={input_k} /> |
39 | | - <button on:click={addVectorFromInput}>Add</button> |
| 43 | + <button on:click={addVectorFromInput}>+</button> |
| 44 | + <button on:click={Initialize}>Reset</button> |
40 | 45 | </div> |
41 | 46 | </main> |
42 | 47 |
|
|
50 | 55 | </body> |
51 | 56 |
|
52 | 57 | <style lang="scss"> |
53 | | - @import "AppStyle"; |
| 58 | + @import "App"; |
54 | 59 | </style> |
0 commit comments