38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
// explizite Freigabe von Einheiten
|
|
|
|
// math.js
|
|
export const add = (a, b) => a + b;
|
|
export const subtract = (a, b) => a - b;
|
|
|
|
// Übung 2: Mathfunktionen als Modul
|
|
|
|
// Programmiere zwei weitere Module, die jeweils eine Funktion multiply und divide enthalten. Importiere die Funktionen in der main.js-Datei und führe sie aus.
|
|
|
|
export const multiply = (a, b) => a * b;
|
|
export const divide = (a, b) => {
|
|
return b === 0 ? NaN : a / b;
|
|
};
|
|
|
|
// Übung 3: Exportieren Funktionen als Objekt
|
|
|
|
// Anstatt die Funktionen add, subtract, multiply und divide benannt zu exportieren, exportiere sie als Standard-Export in einem Objekt. Importiere das Objekt in der main.js-Datei und führe die Funktionen aus.
|
|
|
|
export default {
|
|
add,
|
|
subtract,
|
|
multiply,
|
|
divide,
|
|
// add: add,
|
|
// subtract: subtract,
|
|
// multiply:multiply,
|
|
// divide: divide,
|
|
};
|
|
|
|
// Übung 2: Mathfunktionen als Modul
|
|
|
|
// Programmiere zwei weitere Module, die jeweils eine Funktion multiply und divide enthalten. Importiere die Funktionen in der main.js-Datei und führe sie aus.
|
|
|
|
// Übung 3: Exportieren Funktionen als Objekt
|
|
|
|
// Anstatt die Funktionen add, subtract, multiply und divide benannt zu exportieren, exportiere sie als Standard-Export in einem Objekt. Importiere das Objekt in der main.js-Datei und führe die Funktionen aus.
|