var MC={price:2000000,dpPct:25,rate:2.5,tenure:25};function mcFmt(n){return"S$"+Math.round(n).toLocaleString("en-US")} function mcMonthly(p,annualRate,years){var r=annualRate/100/12,n=years*12;if(p<=0)return 0;if(r===0)return p/n;return p*r*Math.pow(1+r,n)/(Math.pow(1+r,n)-1)} function mcPrice(el){var raw=el.value.replace(/[^0-9]/g,"");el.value=raw?parseInt(raw,10).toLocaleString("en-US"):""MC.price=parseInt(raw||"0",10);mcRender()} function mcDp(v){MC.dpPct=parseInt(v,10);document.getElementById("dpVal").textContent="Down Payment:"+MC.dpPct+"%"mcRender()} function mcRate(v){MC.rate=parseFloat(v);document.getElementById("rateVal").textContent="Interest Rate:"+MC.rate.toFixed(2)+"%"mcRender()} function mcTenure(v){MC.tenure=parseInt(v,10);document.getElementById("tenureVal").textContent="Loan Tenure:"+MC.tenure+"yrs"mcRender()} function mcRender(){var price=MC.price,dpPct=MC.dpPct,rate=MC.rate,tenure=MC.tenure;var down=price*dpPct/100;var loan=price-down;var monthly=mcMonthly(loan,rate,tenure);var totalPay=monthly*tenure*12;var totalInt=totalPay-loan;var pPct=loan>0?Math.round(loan/totalPay*100):0;var iPct=100-pPct;document.getElementById("monthly").textContent=mcFmt(monthly);document.getElementById("monthlySub").textContent="On a"+mcFmt(loan)+"loan at"+rate.toFixed(2)+"%over"+tenure+"years"document.getElementById("loanAmt").textContent=mcFmt(loan);document.getElementById("totalInt").textContent=mcFmt(totalInt);document.getElementById("totalPay").textContent=mcFmt(totalPay);document.getElementById("dpAmt").textContent="="+mcFmt(down)+"down \\u00b7"+mcFmt(loan)+"loan"document.getElementById("stack").querySelector(".s-p").style.width=pPct+"%"document.getElementById("stack").querySelector(".s-i").style.width=iPct+"%"document.getElementById("lgP").textContent=pPct+"%"document.getElementById("lgI").textContent=iPct+"%"document.getElementById("dPrice").textContent=mcFmt(price);document.getElementById("dDown").textContent=mcFmt(down)+"("+dpPct+"%)"document.getElementById("dLoan").textContent=mcFmt(loan);document.getElementById("dRate").textContent=rate.toFixed(2)+"%p.a."document.getElementById("dTenure").textContent=tenure+"years("+(tenure*12)+"months)"document.getElementById("dMonthly").textContent=mcFmt(monthly);document.getElementById("dInt").textContent=mcFmt(totalInt);document.getElementById("dTotal").textContent=mcFmt(totalPay)} if(document.getElementById("monthly")){mcRender()}else{document.addEventListener("DOMContentLiteSpeedLoaded",mcRender)}