scrimba
Practical math
Monthly Expense Sheet - Generate, Display, and Track Expenses
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Monthly Expense Sheet - Generate, Display, and Track Expenses
AboutCommentsNotes
Monthly Expense Sheet - Generate, Display, and Track Expenses
Expand for more info
index.js
run
preview
console
function roll(min, max, floatFlag) {
let r = Math.random() * (max - min) + min
return floatFlag ? r : Math.floor(r)
}

let startDay = new Date("3/15/2020")
let month = buildMonth(startDay)
displayMonth(month)


// Generate a Monthly Budget (Subtract Rent/Utils)

// Generate / Display Random Expenses

// Calculate / Display Leftover Cash



function getNextDay(day) {
let nextDay = new Date(day)
nextDay.setDate(day.getDate() + 1)
return nextDay
}

function buildMonth(day) {
let daysInMonth = getDaysInMonth(day.getMonth() + 1, day.getFullYear())
let iterableDay = new Date(day)
iterableDay.setDate(1)
let month = [...Array(daysInMonth)].map((_, i) => {
let monthDay = {
index: i,
date: iterableDay,
expenses: []
}
iterableDay = getNextDay(iterableDay)
return monthDay
})
return month
}

function getDaysInMonth(month, year) {
return new Date(year, month, 0).getDate()
}

function displayMonth(month) {
let monthHtml = month.reduce(function(accumulator, day) {
return accumulator + `<div class="day">${day.date.getDate()}</div>`
}, '')
document.getElementById('MonthlyExpenses').innerHTML = monthHtml
}
Console
/index.html
-8:10