//On track budget app
$( document ).ready(function() {
var incomeArray = getIncomeArray();
//button interaction
$( "#incomeButton" ).click(function() {
createIncomeItem("income_amount");
console.log(incomeArray);
});
//create initial list
for(var i = 0; i < incomeArray.length; i++){
var key = incomeArray[i];
var value = incomeArray[key];
console.log(key);
addToList(value);
}
});
//reset form after submit
function resetForm(form){
form.reset()
}
function convertToInt(key) {
var numItem = parseInt(localStorage.getItem(key));
console.log(numItem);
//numItem = numItem + 1;
//code
return numItem;
}
function addToList(value) {
var list = document.getElementById("list");
var listItem = document.createElement("li");
var span = document.createElement("span");
span.setAttribute("class", "listItem");
span.innerHTML = value;
listItem.appendChild(span);
list.appendChild(listItem);
//code
}
//income functions
function createIncomeItem(formItem) {
var incomeArray = getIncomeArray();
var currentDate = new Date();
var time = currentDate.getTime();
var key = "income_" + time;
var value = document.getElementById(formItem).value;
incomeArray.push(key);
localStorage.setItem("incomeArray", JSON.stringify(incomeArray));
//console.log(incomeArray);
addToList(value);
//console.log(incomeArray);
//code
}
function getIncomeArray(){
//get or create storage arrays
var incomeArray = localStorage.getItem("incomeArray");
console.log(incomeArray);
if (!incomeArray) {
incomeArray = [];
localStorage.setItem("incomeArray", JSON.stringify(incomeArray));
//code
console.log("there is no array so I made one");
}
else{
incomeArray = JSON.parse(incomeArray);
console.log("there is an array and...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.