JS ARRAYS + RECHNEN?

Also ich habe ein Programm wo man per Knopfdruck über einen Prompt etwas schreiben kann und das steht dann im Array, aber es soll so sein das wenn man auf einen anderen Button drückt ein Allert kommt in dem steht wie viel alles zusammen ist also ich möchte es + rechnen.

Falls es hilfreich ist hier mein Code:

<html>

<head>

  <meta charset="utf-8" />

</head>

<body>

  <h1>Stromverbrauch</h1>

  <button onclick="addNewItem(); updateList();">Neuen Verbrauch hinzufügen</button>

  <ul id="list">

  </ul>

  <script>

    let shoppingItems = getShoppingItemsFromLocalStorage();

    updateList();

    function getShoppingItemsFromLocalStorage() {

      let items = localStorage.getItem('shoppingItems');

      if (items == null || items == '') {

        items = [];

      } else {

        items = items.split(',');

      }

      return items;

    }

    function addNewItem() {

      let item = prompt('Welchen Verbrauch hast du?');

      if (item != null) {

        shoppingItems.push(item);

        localStorage.setItem('shoppingItems', shoppingItems);

      }

    }

    function removeItem(itemIndex) {

      shoppingItems.splice(itemIndex, 1);

      localStorage.setItem('shoppingItems', shoppingItems);

    }

    function updateList() {

      document.getElementById('list').innerHTML = '';

      for (let index = 0; index < shoppingItems.length; index += 1) {

        document.getElementById('list').innerHTML += '<li>' + shoppingItems[index] +

        ' <button onclick="removeItem(' + index + '); updateList();">X</button></li>';

      }

    }

  </script>

</body>

</html>

Computer, programmieren, JavaScript, Informatik
Weitere Inhalte können nur Nutzer sehen, die bei uns eingeloggt sind.