Skip to content

Instantly share code, notes, and snippets.

Created January 8, 2016 11:53
Show Gist options
  • Save anonymous/6d2f3fd5b39b9ee6deeb to your computer and use it in GitHub Desktop.
Save anonymous/6d2f3fd5b39b9ee6deeb to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/zogikewito
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<form id="myform">
<h1>Please enter data</h1>
<input id="salary" type="number" placeholder="Salary" />
<br />
<input id="bills" type="number" placeholder="Bills" />
<br />
<input id="savings" type="number" placeholder="Savings" />
<br />
<input type="button" value="Save/Show" id="subButton"/>
<br />
<input type="button" value="Clear" id="clear"/>
</form>
<div id="salary">
<p id="totalSpend"></p>
</div>
<script id="jsbin-javascript">
// Enter Details
function details() {
var enterSalary = document.getElementById('salary').value;
var enterBills = document.getElementById("bills").value;
var enterSavings = document.getElementById("savings").value;
var salary = parseInt(enterSalary);
var bills = parseInt(enterBills);
var savings = parseInt(enterSavings);
var arr = [salary, bills, savings];
var i = 0;
for (i; i < 3; i++) {
console.log(arr[i]);
}
var totalSpend = bills + savings;
document.getElementById("totalSpend").innerHTML = "Your total net spend is £" + Math.round(totalSpend);
var salaryMinusTotalSpend = salary - totalSpend;
console.log("Your salary, after bills and savings is deducted is " + salaryMinusTotalSpend);
var days = salaryMinusTotalSpend / 30;
console.log("Your daily spend is " + days);
var weeklyTotal = days * 7;
console.log("You can afford to spend " + weeklyTotal + " each week!");
}
// Clear Inputs
function clearInputs () {
document.getElementById('myform').reset();
}
// Buttons
var subButton = document.getElementById('subButton');
subButton.addEventListener('click', details, false);
var clearButton = document.getElementById('clear');
clearButton.addEventListener('click', clearInputs, false);
// Round to Two Decimal Places
function roundToTwo(value) {
return +(Math.round(value + "e+2") + "e-2");
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">// Enter Details
function details() {
var enterSalary = document.getElementById('salary').value;
var enterBills = document.getElementById("bills").value;
var enterSavings = document.getElementById("savings").value;
var salary = parseInt(enterSalary);
var bills = parseInt(enterBills);
var savings = parseInt(enterSavings);
var arr = [salary, bills, savings];
var i = 0;
for (i; i < 3; i++) {
console.log(arr[i]);
}
var totalSpend = bills + savings;
document.getElementById("totalSpend").innerHTML = "Your total net spend is £" + Math.round(totalSpend);
var salaryMinusTotalSpend = salary - totalSpend;
console.log("Your salary, after bills and savings is deducted is " + salaryMinusTotalSpend);
var days = salaryMinusTotalSpend / 30;
console.log("Your daily spend is " + days);
var weeklyTotal = days * 7;
console.log("You can afford to spend " + weeklyTotal + " each week!");
}
// Clear Inputs
function clearInputs () {
document.getElementById('myform').reset();
}
// Buttons
var subButton = document.getElementById('subButton');
subButton.addEventListener('click', details, false);
var clearButton = document.getElementById('clear');
clearButton.addEventListener('click', clearInputs, false);
// Round to Two Decimal Places
function roundToTwo(value) {
return +(Math.round(value + "e+2") + "e-2");
}</script></body>
</html>
// Enter Details
function details() {
var enterSalary = document.getElementById('salary').value;
var enterBills = document.getElementById("bills").value;
var enterSavings = document.getElementById("savings").value;
var salary = parseInt(enterSalary);
var bills = parseInt(enterBills);
var savings = parseInt(enterSavings);
var arr = [salary, bills, savings];
var i = 0;
for (i; i < 3; i++) {
console.log(arr[i]);
}
var totalSpend = bills + savings;
document.getElementById("totalSpend").innerHTML = "Your total net spend is £" + Math.round(totalSpend);
var salaryMinusTotalSpend = salary - totalSpend;
console.log("Your salary, after bills and savings is deducted is " + salaryMinusTotalSpend);
var days = salaryMinusTotalSpend / 30;
console.log("Your daily spend is " + days);
var weeklyTotal = days * 7;
console.log("You can afford to spend " + weeklyTotal + " each week!");
}
// Clear Inputs
function clearInputs () {
document.getElementById('myform').reset();
}
// Buttons
var subButton = document.getElementById('subButton');
subButton.addEventListener('click', details, false);
var clearButton = document.getElementById('clear');
clearButton.addEventListener('click', clearInputs, false);
// Round to Two Decimal Places
function roundToTwo(value) {
return +(Math.round(value + "e+2") + "e-2");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment