Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Budge App Project</title>
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
    />
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <header>
      <h1 id="title">Budget App</h1>
    </header>

    <div id="outter-container">
      <!-- COLUMN 1 -->
      <div id="budget-container">
        <form>
          <label>Enter Your Budget</label>
          <input type="number" id="budgetInput" />
          <button type="button" id="calcBtn">Add Budget</button>
          <div id="budget-error-message"></div>
        </form>
      </div>

      <!-- COLUMN 3 -->
      <div id="expenseEntry-container">
        <form>
          <label>Enter Your Expense</label>
          <input type="text " id="expenseInput" />
          <label>Enter Your Expense Amount</label>
          <input type="number" id="expenseAmountInput" />
          <button type="button" id="expenseBtn">Add Expense</button>
          <div id="expense-error-message"></div>
        </form>
      </div>

      <!-- COLUMN 2 -->
      <div id="balanceDisplay-container">
        <div id="budgetTotalAmount">
          <h2>Budget</h2>
          <i class="fa fa-money" aria-hidden="true"></i>
          <h3 id="budgetMoney" class="moneyOutput text-green">$0</h3>
        </div>

        <div id="expensesTotalAmount">
          <h2>Expenses</h2>
          <i class="fa fa-credit-card-alt" aria-hidden="true"></i>
          <h3 id="expensesMoney" class="moneyOutput text-red">$0</h3>
        </div>

        <div id="balanceTotalAmount">
          <h2>Balance</h2>
          <i class="fa fa-dollar" aria-hidden="true"></i>
          <h3 id="balanceMoney" class="moneyOutput text-green">$0</h3>
        </div>
      </div>

      <!-- COLUMN 4 -->
      <div id="expenses-container">
        <table id="table-list">
          <tr>
            <th>Expense Title</th>
            <th>Expense Value</th>
            <th></th>
          </tr>
        </table>
      </div>
    </div>

    <script src="app.js"></script>
    <script>
      //https://jsbeginners.com/page/2/
    </script>
  </body>
</html>

              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background: #f0f0f0;
  font-family: Lato;
  min-height: 100vh;
}

header {
  background: rgb(0, 0, 0);
  padding: 0.35rem;
}

header h1 {
  line-height: 4px;
  color: white;
  text-align: center;
  font-size: 1.5rem;
}

/* GRID SYSTEM */

#outter-container {
  padding: 0.5rem 2rem;
  margin-top: 20px;
  display: grid;
  grid-template-columns: 38% 55%;
  column-gap: 70px;
  row-gap: 50px;
}

/*_________________BUDGET FORM_____________________*/

#budget-container {
  border: 2px solid green;
  padding: 1rem;
  border-radius: 5px;
  order: 1;
}

#budget-container label {
  display: block;
  font-size: 1.5rem;
}

#budget-container input {
  width: 95%;
  display: block;
  margin: 25px 0;
  padding: 0.25rem;
  font-size: 1.4rem;
  text-align: center;
  border-radius: 5px;
  border: 1px solid green;
  outline: green;
}
#budget-container input:focus {
  box-shadow: 0 0 5px 0px black; /* blurr effect */
}

#budget-container button {
  display: block;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid green;
  color: green;
  margin-top: 35px;
  outline: none;
  font-size: 1rem;
  transition: all 0.2s ease-in-out;
}

#budget-container button:hover {
  background: green;
  color: white;
  cursor: pointer;
}

#budget-container button:active {
  background: darkgreen;
}

/*______________________________EXPENSE FORM__________________________ */

#expenseEntry-container {
  border: 2px solid rgb(150, 0, 0);
  padding: 0.75rem;
  border-radius: 5px;
  order: 3;
}

#expenseEntry-container label {
  display: block;
  font-size: 1.2rem;
}

#expenseEntry-container input {
  width: 95%;
  display: block;
  margin: 10px 0;
  padding: 0.25rem;
  text-align: center;
  font-size: 1.4rem;
  border-radius: 5px;
  border: 1px solid rgb(150, 0, 0);
  outline: rgb(150, 0, 0);
}

#expenseEntry-container input:focus {
  box-shadow: 0 0 5px 0px black; /* blurr effect */
}

#expenseEntry-container button {
  display: block;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid rgb(150, 0, 0);
  color: rgb(150, 0, 0);
  margin: 5px 0;
  font-size: 1rem;
  outline: none;
}

#expenseEntry-container button:hover {
  cursor: pointer;
  background-color: rgb(150, 0, 0);
  color: white;
  transition: all 0.2s ease-in-out;
}

#expenseEntry-container button:active {
  background-color: rgb(97, 0, 0);
}

/* __________________________BALANCE DISPLAY SECTION__________________________ */

#balanceDisplay-container {
  display: flex;
  justify-content: space-between;
  order: 2;
}

#balanceDisplay-container > * {
  padding: 0.25rem;
}

#balanceDisplay-container i {
  /*font awesome icons */
  font-size: 4rem;
  color: rgb(0, 53, 122);
  display: inline-block;
  width: 100%;
  text-align: center;
  margin: 20px 0;
}

#balanceDisplay-container h2 {
  text-transform: uppercase;
  text-align: center;
  color: rgb(77, 77, 77);
  margin: 0;
}

#balanceDisplay-container .moneyOutput {
  font-size: 2.25rem;
  text-align: center;
  margin: 0;
}

.text-red {
  color: rgb(180, 0, 0);
}
.text-green {
  color: green;
}

/*______________________EXPENSES DISPLAY _______________________________*/
#expenses-container {
  /* border: 1px solid black; */
  order: 4;
  width: 100%;
  height: 230px;
  overflow-y: scroll;
}
#table-list {
  width: 100%;
  padding: 0;
}

#expenses-container h2 {
  font-size: 1.1rem;
}

#table-list th {
  text-align: left;
  padding: 0.5rem;
  font-size: 1.1rem;
  border-bottom: 1px solid rgb(119, 119, 119);
}

#table-list td {
  padding: 0.5rem;
  color: rgb(180, 0, 0);
  font-size: 1.4rem;
  border-bottom: 1px solid lightgray;
}

.icons {
  text-align: right;
}
#table-list i {
  margin-bottom: 8px;
  font-size: 1.5rem;
  padding: 0 0.2rem;
  cursor: pointer;
}

#table-list i:hover {
  color: black;
}

.editBtn {
  color: rgb(0, 53, 122);
}

.removeBtn {
  color: rgb(180, 0, 0);
}

/* ERROR MESSAGES */
.error-active {
  margin-top: 10px;
  padding: 1rem;
  font-size: 1.1rem;
  background: rgb(255, 95, 95);
  color: white;
}

/* ____________________________MEDIA QUERY FOR RESPONSIVE DESIGN____________________________ */
@media screen and (max-width: 1100px) {
  #outter-container {
    column-gap: 20px;
  }
}
@media screen and (max-width: 760px) {
  #outter-container {
    grid-template-columns: 1fr;
    row-gap: 30px;
  }
  #budget-container {
    order: 1;
  }
  #expenseEntry-container {
    order: 2;
  }
  #balanceDisplay-container {
    order: 3;
  }
  #expenses-container {
    order: 4;
  }
}

              
            
!

JS

              
                var budgetInput = document.querySelector("#budgetInput");
var expenseTitle = document.querySelector("#expenseInput");
var expenseAmount = document.querySelector("#expenseAmountInput");
var totalExpensesList = [];
var budget = 0;

//Budget Entry
document.querySelector("#calcBtn").addEventListener("click", function() {
  if (budgetInput.value.trim() === "") {
    var budgetErrorMsg = document.querySelector("#budget-error-message");
    displayErrorMessage(budgetErrorMsg,"Please, Enter a Valid Number in the Budget Field");
  } else {
    budget = budgetInput.value;
    document.querySelector("#budgetMoney").innerHTML = "$" + budget;
    budgetInput.value = "";
  }
});

//Expenses List
document.querySelector("#expenseBtn").addEventListener("click", function() {
  var number = expenseAmount.value;
  var name = expenseTitle.value;
  if (expenseTitle.value.trim() === "" || expenseAmount.value.trim() === "") {
    var expenseErrorMsg = document.querySelector("#expense-error-message");
    displayErrorMessage(expenseErrorMsg,"Please, Enter a Expense Title AND Amount");
  } else {
    var editIcon = document.createElement("i");
    editIcon.classList.add("fa", "fa-pencil-square-o", "editBtn");
    editIcon.addEventListener("click", function() {
      editItem(this, number, name);
    });

    var removeIcon = document.createElement("i");
    removeIcon.classList.add("fa", "fa-trash", "removeBtn");
    removeIcon.addEventListener("click", function() {
      removeItem(this, number);
    });

    var table = document.querySelector("table");
    var new_row = document.createElement("tr");
    var icons_td = document.createElement("td");
    icons_td.appendChild(editIcon);
    icons_td.appendChild(removeIcon);

    totalExpensesList.push(number);
    new_td_title = document.createElement("td");
    new_td_title.classList.add("expense-title");
    new_td_title.innerHTML = expenseTitle.value;

    new_td_amount = document.createElement("td");
    new_td_amount.classList.add("expense-amount");
    new_td_amount.innerHTML = "$" + expenseAmount.value;

    new_td_icons = document.createElement("td");
    new_td_icons.classList.add("icons");
    new_td_icons.appendChild(editIcon);
    new_td_icons.appendChild(removeIcon);

    new_row.appendChild(new_td_title);
    new_row.appendChild(new_td_amount);
    new_row.appendChild(new_td_icons);
    table.appendChild(new_row);

    expenseTitle.value = "";
    expenseAmount.value = "";
  }
});

//ExpensesDisplay
function expensesSum() {
  var expensesSum = 0;
  for (let i = 0; i < totalExpensesList.length; i++) {
    expensesSum += parseInt(totalExpensesList[i]);
  }
  return expensesSum;
}
setInterval(function() {
  document.querySelector("#expensesMoney").innerHTML = "$" + expensesSum();
}, 100);

//Balance Display
function balanceDisplay() {
  var balanceText = document.querySelector("#balanceMoney");
  var balanceValue = budget - expensesSum();
  if (balanceValue > 0) {
    balanceText.style.color = "green";
  } else if (balanceValue < 0) {
    balanceText.style.color = "rgb(180,0,0)";
  } else {
    balanceText.style.color = "black";
  }
  balanceText.innerHTML = "$" + balanceValue;
}

setInterval(balanceDisplay, 10);

//
//Font awesome buttons : Remove and Edit:

//Remove button (Font awesome icon)
function removeItem(object, number) {
  //
  object.parentElement.parentElement.remove(); 
  var newExpensesList = [];
  for (let i = 0; i < totalExpensesList.length; i++) {
    if (totalExpensesList[i] != number) {
      newExpensesList.push(parseInt(totalExpensesList[i]));
    }
  }
  console.log(newExpensesList);
  totalExpensesList = newExpensesList;
  console.log("The old array should be updated, " + totalExpensesList);
}

//Edit button (Font awesome Icon)
function editItem(object, number, name) {
  removeItem(object, number);
  expenseTitle.value = name;
  expenseAmount.value = number;
  document.querySelector("#expenseBtn").focus();
}

function displayErrorMessage(obj, text) {
  obj.classList.add("error-active");
  obj.innerHTML = text;
  setTimeout(function() {
    obj.classList.remove("error-active");
    obj.innerHTML = "";
  }, 2500);
}

              
            
!
999px

Console