Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:modul:m291:learningunits:lu07:aufgaben:09 [2025/05/19 13:15] – vdemir | en:modul:m291:learningunits:lu07:aufgaben:09 [2025/05/20 12:58] (aktuell) – [Assignment G: Implementation of the calculation - 10'] vdemir | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ====== LU07.A10 - Basic caluclator | + | ====== LU07.A09 - Basic caluclator |
===== Prerequisites | ===== Prerequisites | ||
* Work type: Individual | * Work type: Individual | ||
* Means of aid: only teaching materials, no websearch, no use of ai. | * Means of aid: only teaching materials, no websearch, no use of ai. | ||
- | * Timeframe: | + | * Timeframe: |
* Expected result: A browser based calulator which can sum up 2 digits in the easiest way. | * Expected result: A browser based calulator which can sum up 2 digits in the easiest way. | ||
===== Source ===== | ===== Source ===== | ||
- | * You can take any script an adjust it to your needs. | + | {{ : |
===== Assignment ===== | ===== Assignment ===== | ||
- | This assignment compraises the programming | + | In LU06.S08 we were programming a basic calulator by manipulation the values directly when clicking the buttons. This is convenient, but limits the possibilities of the calculator significantly. For example handling |
- | ===== Assignment A - 3' | + | Thus, it is basically a similar assignment, but this time by using methods: |
- | * A01: Create in Webstorm in your directory **07_methods** a html file and name it correctly | + | * to set values of diggit1, diggit2 and the operator |
- | * A02: Copy the structure of the sfc (single file component) from a solution of your choice (in that way we don't have to type it manually --> easier and faster) | + | * to calulate the result |
- | * A03: Make sure to have | + | * to reset all values of the variables |
+ | |||
+ | ==== Assignment A - 3' ===== | ||
+ | * A01: Copy the solution of LU06.s08 | ||
+ | * A02: Make sure to have | ||
* the assignmen number in <h1> and | * the assignmen number in <h1> and | ||
* the description in < | * the description in < | ||
- | * A04: Safe it. | + | * A03: Safe it. |
- | ===== Assignment | + | ==== Assignment |
- | * B01: Create | + | * B01: method **setDiggit1(number)**: |
- | * B02: When clicking on one of them the content will be saved in the variable **diggit1** | + | * B02: method **setDiggit2(number)**: |
- | * | + | * B03: method |
- | ===== Assignment C - Variables - 5' ===== | + | * B04: method **calcResult(op)**: |
- | * C01: A basic calculation | + | * B05: method **reset()**: |
- | | + | |
- | | + | |
- | * diggit2 = 0, | + | |
- | * result | + | |
- | ===== Assignment | + | ==== Assignment |
- | * D01: Create the second set of buttons 1 to 4 to set the second diggit. (4 of them shall suffice for our purpose) | + | * C01: A basic calculation, |
- | * D02: When clicking on one of them the content will be saved in the variable | + | * C02: Set in the data-area: |
+ | | ||
+ | * C04: diggit2: 0 | ||
+ | | ||
- | ===== Assignment | + | ==== Assignment |
- | * E01: To execute our addition-operation we finally need a button | + | * D01: When clicking on the diggit keys of block one the content will be saved in the variable |
- | * E02: This enter calls a method | + | * D02: But unlike in the previous task, this time the click triggers |
- | * E03: Thus the addition is done in the method, correspondingly to the providet | + | * D03: Continue with the other three buttons in the same fashion. |
- | * E04: As a result, after pressing | + | * D04: Check the result by displaying the content of the variable **diggit1** on the display. |
+ | |||
+ | ==== Assignment E - Button the operation - 5' ==== | ||
+ | * E01: When clicking the **+**-button the content will be saved in the variable **operator** | ||
+ | * E02: Check the result by displaying the content of the variable **operator** on the screen. | ||
+ | * **Hint:** The other three basic operations (subtraktion, multiplication, | ||
+ | |||
+ | ==== Assignment F - Button for diggit 2 - 5' ==== | ||
+ | * F01: When clicking on the button | ||
+ | * F02: But unlike in the previous task, this time the click triggers a method **setDiggit2(dig2)** | ||
+ | * F03: Continue with the other three buttons in the same fashion. | ||
+ | * F04: Check the result by displaying the content of the variable **diggit2** on the display. | ||
+ | ==== Assignment G: Implementation of the calculation - 10' | ||
+ | * G01: To execute our addition-operation we finally need a button **ENTER**. This triggers the method **caldResult()**. | ||
+ | * G02: All relevant variables (diggit1, operator, diggit2) are set know, we are ready to finalize our calculation. | ||
+ | * G03: In the method **calcResult** we need to execute the calculation bases on the provided **operator**. | ||
+ | * If the operator is a **+** we calculate our result as **this.result = this.diggit1 + this.diggit2" | ||
+ | * And subsequently, | ||
+ | * The Multiplication and the division a conducted in the same fashion. | ||
+ | * G04: Finally have the **result** displayed on the screen to check the correctness of your efforts. | ||
===== Solution ===== | ===== Solution ===== | ||
Zeile 49: | Zeile 71: | ||
^ English ^ German ^ | ^ English ^ German ^ | ||
| diggit | Ziffer | | | diggit | Ziffer | | ||
- | | to suffice | + | | initial values | Startwerte | |
- | | respectively | beziehungungsweise | + | | to conduct |
+ | | respectively | beziehungsweise | ||
| to compraise | umfassen | | | to compraise | umfassen | | ||
- | | several | einige, etliche | | ||
- | |||