const randomIntNumbers = n => { let transaktionen = []; for (let i = 0; i < n; i++) { const rndNum = Math.random() * 1000; rndNum > Math.random() * 1000 ? transaktionen.push(Math.trunc(rndNum)) : transaktionen.push(-Math.trunc(rndNum)); } return transaktionen; }; const arrOfTrans = randomIntNumbers(10); console.log(`Alle Transaktionen: ${arrOfTrans}`); const saldo = arrOfTrans.reduce(function (accu, cur, index) { const transaktion = cur > 0 ? "deposit" : "witdrawal"; console.log( `Konto Status: ${accu}, Transaktion ${index}: ${cur} (${transaktion})` ); return accu + cur; }); console.log(`Saldo: ${saldo} EUR`);