diff --git a/javascript/Javascript Expert/chapter11/arrayMethods.js b/javascript/Javascript Expert/chapter11/arrayMethods.js new file mode 100644 index 0000000..cd7ad69 --- /dev/null +++ b/javascript/Javascript Expert/chapter11/arrayMethods.js @@ -0,0 +1,42 @@ +let arr = ["a", "b", "c", "d", "e", "f"]; +// ['c', 'd', 'e', 'f'] +arr = arr.slice(2); +console.log(arr); + +// ['e', 'f'] +arr = arr.slice(2, arr.length); +console.log(arr); + +// Das Feld mit den ursprünlichen Werten zurücksetzen +arr = ["a", "b", "c", "d", "e", "f"]; +arr = arr.slice(-2); +// ['e', 'f'] +console.log(arr); + +arr = ["a", "b", "c", "d", "e", "f"]; +arr = arr.slice(); +console.log(...arr); + +arr = ["a", "b", "c", "d", "e", "f"]; +// mit der splice Methode wird der Inhalt des Feldes geändert, bei der slice Methode wird der Inhalt des Feldes nicht geändert(da wird Änderung nur zurück gegeben) +console.log(arr.splice(2)); // wird der entfernte Teil des Feldes zurück gegeben ("[c", "d", "e", "f"]), und der turuckgegebene Teil entfernt aus dem Feld +console.log(arr); // ["a", "b", "c", "d", "e", "f"].splice(2), arr = ["a", "b"] + +arr = ["a", "b", "c", "d", "e", "f"]; +arr.splice(-1); // ["f"] +console.log(arr); //["a", "b", "c", "d", "e"] + +arr = ["a", "b", "c", "d", "e", "f"]; +arr.splice(1, 2); +console.log(arr); + +arr = ["a", "b", "c", "d", "e", "f"]; +const arr2 = arr.reverse(); // mutable Methode (ändert das originale Fels (arr), und ändert Werte, in der umgekehrten Reie) +console.log(arr); + +arr = ["a", "b", "c", "d", "e", "f"]; +const arrMerged = arr.concat(arr2); +console.log(arrMerged); +// dasselbe als die Anweisung unten +console.log([...arr, ...arr2]); +console.log(arrMerged.join("-")); diff --git a/javascript/Javascript Expert/chapter11/index.html b/javascript/Javascript Expert/chapter11/index.html new file mode 100644 index 0000000..ff41140 --- /dev/null +++ b/javascript/Javascript Expert/chapter11/index.html @@ -0,0 +1,12 @@ + + + + + + + Working with Arrays + + + + + diff --git a/javascript/Javascript Expert/chapter11/template.js b/javascript/Javascript Expert/chapter11/template.js new file mode 100644 index 0000000..882d298 --- /dev/null +++ b/javascript/Javascript Expert/chapter11/template.js @@ -0,0 +1,71 @@ +"use strict"; +// Data +const account1 = { + owner: "David Aster", + movements: [200, 450, -400, 3000, -650, -130, 70, 1300], + interestRate: 1.2, // % + pin: 1111, +}; + +const account2 = { + owner: "Joanne Aster", + movements: [5000, 3400, -150, -790, -3210, -1000, 8500, -30], + interestRate: 1.5, + pin: 2222, +}; + +const account3 = { + owner: "Nika Aster", + movements: [200, -200, 340, -300, -20, 50, 400, -460], + interestRate: 0.7, + pin: 3333, +}; + +const account4 = { + owner: "Eva Aster", + movements: [430, 1000, 700, 50, 90], + interestRate: 1, + pin: 4444, +}; + +const accounts = [account1, account2, account3, account4]; + +// Elements +const labelWelcome = document.querySelector(".welcome"); +const labelDate = document.querySelector(".date"); +const labelBalance = document.querySelector(".balance__value"); +const labelSumIn = document.querySelector(".summary__value--in"); +const labelSumOut = document.querySelector(".summary__value--out"); +const labelSumInterest = document.querySelector(".summary__value--interest"); +const labelTimer = document.querySelector(".timer"); + +const containerApp = document.querySelector(".app"); +const containerMovements = document.querySelector(".movements"); + +const btnLogin = document.querySelector(".login__btn"); +const btnTransfer = document.querySelector(".form__btn--transfer"); +const btnLoan = document.querySelector(".form__btn--loan"); +const btnClose = document.querySelector(".form__btn--close"); +const btnSort = document.querySelector(".btn--sort"); + +const inputLoginUsername = document.querySelector(".login__input--user"); +const inputLoginPin = document.querySelector(".login__input--pin"); +const inputTransferTo = document.querySelector(".form__input--to"); +const inputTransferAmount = document.querySelector(".form__input--amount"); +const inputLoanAmount = document.querySelector(".form__input--loan-amount"); +const inputCloseUsername = document.querySelector(".form__input--user"); +const inputClosePin = document.querySelector(".form__input--pin"); + +///////////////////////////////////////////////// +///////////////////////////////////////////////// +// LECTURES + +const currencies = new Map([ + ["USD", "United States dollar"], + ["EUR", "Euro"], + ["GBP", "Pound sterling"], +]); + +const movements = [200, 450, -400, 3000, -650, -130, 70, 1300]; + +/////////////////////////////////////////////////