Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="widget-wrap">
  <h1>JS BUDGET PLANNER</h1>
  
  <!-- (A) SUMMARY -->
  <div id="summary">
    <!-- (A1) BALANCE -->
    <div id="balance">
      <div id="balanceTxt">Balance</div>
      <div id="balanceAmt">$0</div>
    </div>

    <!-- (A2) INCOME -->
    <div id="income">
      <div id="incomeTxt">Income</div>
      <div id="incomeAmt">$0</div>
    </div>

    <!-- (A3) EXPENSE -->
    <div id="expense">
      <div id="expenseTxt">Expense</div>
      <div id="expenseAmt">$0</div>
    </div>
  </div>

  <!-- (B) ENTRIES LIST -->
  <div id="entries">
    <div id="dummy" onclick="bg.toggle(true)">New Entry</div>
    <div id="list"></div>
  </div>

  <!-- (C) ENTRY FORM -->
  <div id="form"><form onsubmit="return bg.save()">
    <div id="formEnd" onclick="bg.toggle(false)">X</div>
    <input type="hidden" id="formID">
    <label>Income/Expense</label>
    <select id="formSign" required>
      <option value="+">Income</option>
      <option value="-">Expense</option>
    </select>
    <label>Description</label>
    <input type="text" id="formTxt" required>
    <label>Amount</label>
    <input type="number" id="formAmt" step="0.01" required>
    <input type="submit" value="Save" id="formGo">
  </form></div>
  
  <!-- (X) VISIT CODE-BOXX -->
  <div id="code-boxx">
    Visit
    <a href="https://code-boxx.com/simple-budget-planner-javascript/" target="_blank">
      Code Boxx
    </a> for more details.
  </div>
 </div>
              
            
!

CSS

              
                /* (A) SUMMARY */
/* (A1) WRAPPER */
#summary {
  display: grid;
  grid-template-areas: "b b" "i e";
  grid-gap: 10px;
  padding: 20px;
  font-weight: 700;
  background: #1c5d95;
}
#balance, #income, #expense { padding: 10px; }
#balance { grid-area: b; }
#income { grid-area: i; }
#expense { grid-area: e; }

/* (A2) BALANCE */
#balanceTxt { color: #7b9cd7; }
#balanceAmt {
  font-size: 38px;
  color: #fff;
}

/* (A3) INCOME & EXPENSE */
#income, #expense {
  border-radius: 10px;
  background: #fff;
}
#incomeAmt, #expenseAmt { font-size: 28px; }
#incomeTxt { color: #92e7a1; }
#expenseTxt { color: #e5a5a5; }
#incomeAmt { color: #41b941; }
#expenseAmt { color: #d72f2f; }

/* (B) ENTRIES LIST */
#entries { padding: 10px; }
#dummy, .eDel, .eEdit { cursor: pointer; }
#dummy, .entry {
  border-radius: 15px;
  margin: 20px 0;
  padding: 20px;
}
#dummy {
  font-weight: 700;
  color: #959595;
  border: 3px dashed #d3d3d3;
}
.entry {
  display: flex;
  background: #fff;
  align-items: center;
  font-size: 18px;
}
.eDel, .eTxt, .eAmt, .eEdit { padding: 0 10px; }
.eDel, .eAmt, .eEdit { font-weight: 700; }
.eDel { color: #d72f2f; }
.eTxt { flex-grow: 1; }
.eEdit, .income .eTxt, .expense .eTxt { color: #959595; }
.income .eAmt { color: #41b941; }
.expense .eAmt { color: #d72f2f; }

/* (C) ITEM FORM */
#form {
  /* (C1) FULLSCREEN */
  position: fixed;
  top: 0; left: 0; z-index: 999;
  width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.5);

  /* (C2) CENTERED CONTAINER */
  display: flex;
  align-items: center;
  justify-content: center;

  /* (C3) HIDDEN BY DEFAULT */
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s;
}

/* (C4) SHOW FORM */
#form.show {
  visibility: visible;
  opacity: 1;
}

/* (C5) FORM ITSELF */
#form form {
  min-width: 400px;
  max-width: 600px;
  padding: 20px;
  border-radius: 10px;
  background: #fff;
  position: relative;
}

/* (C6) FORM ELEMENTS */
#formEnd, #formGo { cursor: pointer; }
#formEnd {
  position: absolute;
  top: 0; right: 0;
  padding: 10px;
  font-weight: 700;
  color: #fff;
  background: #ab2020;
}
#form label, #form input, #form select {
  display: block;
  width: 100%;
}
#form label {
  margin: 10px 0;
  color: #b3b3b3;
}
#form input, #form select { padding: 15px; }
#formGo {
  margin-top: 20px;
  border: 0;
  color: #fff;
  background: #1f3e95;
}

/* (X) DOES NOT MATTER */
/* PAGE & BODY */
* {
  font-family: arial, sans-serif;
  box-sizing: border-box;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: url(https://images.unsplash.com/photo-1573848855919-9abecc93e456?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc3Njk0NDA&ixlib=rb-1.2.1&q=80);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

/* WIDGET */
.widget-wrap {
  width: 800px; 
  padding: 20px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
}

/* FOOTER */
#code-boxx {
  font-weight: 600;
  margin-top: 30px;
}
#code-boxx a {
  display: inline-block;
  border: 0;
  padding: 5px;
  text-decoration: none;
  background: #b90a0a;
  color: #fff;
}
              
            
!

JS

              
                var bg = {
  // (A) INITIALIZE
  data : null, // entries data
  hBal : null, // html balance amount
  hInc : null, // html income amount
  hExp : null, // html expense amount
  hList : null, // html entries list
  hForm : null, // html form wrapper
  fID : null, fSign : null, fTxt : null, fAmt : null, // html form fields
  init : () => {
    // (A1) GET HTML ELEMENTS
    bg.hBal = document.getElementById("balanceAmt");
    bg.hInc = document.getElementById("incomeAmt");
    bg.hExp = document.getElementById("expenseAmt");
    bg.hList = document.getElementById("list");
    bg.hForm = document.getElementById("form");
    bg.fID = document.getElementById("formID");
    bg.fSign = document.getElementById("formSign");
    bg.fTxt = document.getElementById("formTxt");
    bg.fAmt = document.getElementById("formAmt");

    // (A2) LOAD ENTRIES
    bg.entries = localStorage.getItem("entries");
    if (bg.entries==null) { bg.entries = []; }
    else { bg.entries = JSON.parse(bg.entries); }

    // (A3) DRAW ENTRIES
    bg.draw();
  },

  // (B) TOGGLE FORM
  toggle : id => {
    if (id===false) {
      bg.fID.value = "";
      bg.fSign.value = "+";
      bg.fTxt.value = "";
      bg.fAmt.value = "";
      bg.hForm.classList.remove("show");
    } else {
      if (Number.isInteger(id)) {
        bg.fID.value = id;
        bg.fSign.value = bg.entries[id].s;
        bg.fTxt.value = bg.entries[id].t;
        bg.fAmt.value = bg.entries[id].a;
      }
      bg.hForm.classList.add("show");
    }
  },

  // (C) DRAW ENTRIES
  draw : () => {
    // (C1) BALANCE, INCOME, EXPENSES
    let bal = 0, inc = 0, exp = 0, row;

    // (C2) LOOP & DRAW HTML ENTRIES
    bg.hList.innerHTML = "";
    bg.entries.forEach((entry, i) => {
      if (entry.s=="+") {
        inc += entry.a;
        bal += entry.a;
      } else {
        exp += entry.a;
        bal -= entry.a;
      }
      row = document.createElement("div");
      row.className = `entry ${entry.s=="+"?"income":"expense"}`;
      row.innerHTML = `<div class="eDel" onclick="bg.del(${i})">X</div>
      <div class="eTxt">${entry.t}</div>
      <div class="eAmt">$${parseFloat(entry.a).toFixed(2)}</div>
      <div class="eEdit" onclick="bg.toggle(${i})">&#9998;</div>`;
      bg.hList.appendChild(row);
    });

    // (C3) UPDATE TOTALS
    bg.hBal.innerHTML = bal<0 ? `-$${Math.abs(bal).toFixed(2)}` : `$${bal.toFixed(2)}` ;
    bg.hInc.innerHTML = `$${inc.toFixed(2)}`;
    bg.hExp.innerHTML = `$${exp.toFixed(2)}`;
  },

  // (D) SAVE ENTRY
  save : () => {
    // (D1) GET DATA
    let data = {
      s : bg.fSign.value,
      t : bg.fTxt.value,
      a : parseFloat(bg.fAmt.value)
    };

    // (D2) UPDATE ENTRIES ARRAY
    if (bg.fID.value=="") { bg.entries.push(data); }
    else { bg.entries[parseInt(bg.fID.value)] = data; }
    localStorage.setItem("entries", JSON.stringify(bg.entries));

    // (D3) UPDATE HTML INTERFACE
    bg.toggle(false);
    bg.draw();
    return false;
  },

  // (E) DELETE ENTRY
  del : id => { if (confirm("Delete entry?")) {
    bg.entries.splice(id, 1);
    localStorage.setItem("entries", JSON.stringify(bg.entries));
    bg.draw();
  }}
};
window.onload = bg.init;
              
            
!
999px

Console