{"action":"created","comment":{"url":"https://api.github.com/repos/ga-dc/atm/pulls/comments/34744677","id":34744677,"diff_hunk":"@@ -1,21 +1,110 @@\n-var checkingBalance = document.querySelector(\"div#checking_balance\");\n-checkingBalance = parseInt( checkingBalance.innerHTML.replace(\"$\", \"\") );\n+$(document).ready( function() {\n \n-var checkingDeposit = function(amount){\n-  checkingBalance = parseInt( checkingBalance.innerHTML.replace(\"$\", \"\") );\n+//change css property of div.balance to #FF003E\n+$(\"div.balance\").css({\n+    \"background-color\": \"#FF003E\",\n+    \"border-radius\": \"10px\"\n+    });\n \n-}\n+// - As a user, I want to deposit money into one of the bank accounts\n+//set up event listener for click on the Deposit button\n+$(\"#checkingAddMoney\").on(\"click\", addUpTheMoney);\n+$(\"#savingsAddMoney\").on(\"click\", addUpTheMoney);\n \n-function checkingWithdrawal(amount){\n+//set up event listener for click on the Withdrawal button\n+$(\"#withdrawFromChecking\").on(\"click\", subtractMoney);\n+$(\"#withdrawFromSavings\").on(\"click\", subtractMoney);\n \n-}\n+// on \"deposit\" button click, execute this function\n+function addUpTheMoney(){\n+    //get the current balance of the account we're accessing\n+    var prevBalance = $(this).siblings(\"div.balance\");\n+    var result = prevBalance.text();\n+    //get the current account balance without the $\n+    var currentBalance = parseInt(result.replace(\"$\", \"\"));\n \n-function savingsDeposit(amount){\n+    //get value of the input and set as var newEntry\n+    var newEntry = parseInt($(this).siblings(\"input.moneyInTheBank\").val());\n+\n+    // add value of newEntry to text content of our account\n+    $(prevBalance).text( function(){\n+        var total = newEntry + currentBalance;\n+        return \"$\" + total;\n+    });\n+    // clear the value of the input field\n+    $(this).siblings(\"input.moneyInTheBank\").val(\"\");\n+    // set the background-color of the account to grey when money is addded\n+    $(this).siblings(\"div.balance\").css(\"background-color\", \"#E3E3E3\")\n+}\n \n+// set up a variable and a function to total up the balance of money in both accounts\n+var balanceSum;\n+function getSumBalances() {\n+    var cBalance = $(\"#checkingBalance\").text();\n+    var checkingBalance = parseInt(cBalance.replace(\"$\", \"\"));\n+    var sBalance = $(\"#savingsBalance\").text();\n+    var savingsBalance = parseInt(sBalance.replace(\"$\", \"\"));\n+    balanceSum = savingsBalance + checkingBalance;\n+    return balanceSum;\n }\n+// on \"withdraw\" click =\n+function subtractMoney() {\n+    getSumBalances();\n+    //get the current balance of the account we're accessing\n+    var prevBalance = $(this).siblings(\"div.balance\");\n+    var result = prevBalance.text();\n+    //get the current account balance without the $\n+    var currentBalance = parseInt(result.replace(\"$\", \"\"));\n+    //get value of the input and set as var newWithdrawal\n+    var newWithdrawal = parseInt($(this).siblings(\"input.moneyInTheBank\").val());\n \n-function savingsWithdrawal(amount){\n+    // subtract value of html of div.balance\n+    $(prevBalance).text( function(){\n+        // get the new total balance\n+        var total = currentBalance - newWithdrawal;\n \n+        // setting up overdraft protection with and if-else statement! first we set up the savings half of the function\n+        if ($(this) == $(\"#withdrawFromSavings\")){\n+            // if newWithdrawal would take the account into negatives, ignore newWithdrawal\n+            if (total > 0){\n+                return \"$\" + total;\n+            } else {\n+                return \"$\" + currentBalance;\n+            }\n+        //if the withdrawal comes from checking, we run this part of the function\n+        } else if (newWithdrawal > balanceSum){\n+            alert(\"Not enough money for that!\")\n+        } else {\n+            // if the total is >0, print the new total\n+            if (total > 0){\n+                return \"$\" + total;\n+            // in case of over draft, run this portion of the function:\n+            }  else {\n+                var confirmOverdraft = confirm(\"Do you want to overdraft your account?\");\n+                if (confirmOverdraft == true){\n+                // set the savings balance to the overdrafted amount\n+                $(\"#savingsBalance\").text( function(){\n+                    // get the current savings balance. It wasn't working for me when I tried to do it in one variable, so I split into two\n+                    var stringBalance = $(\"#savingsBalance\").text();\n+                    var savingsBalance = parseInt(stringBalance.replace(\"$\", \"\"));\n+                    // add savings balance and total (because total is a negative value, it should end up being subtracted)\n+                    var overdraft = savingsBalance + total;\n+                    //new savings account balance!\n+                    return \"$\" + overdraft;\n+                });\n+                // change balance to 0 in checking. sad face.","path":"atm.js","position":104,"original_position":104,"commit_id":"f1afcb67a94ee99edcdc40d6d667ba83174d6093","original_commit_id":"f1afcb67a94ee99edcdc40d6d667ba83174d6093","user":{"login":"jshawl","id":3824954,"avatar_url":"https://avatars.githubusercontent.com/u/3824954?v=3","gravatar_id":"","url":"https://api.github.com/users/jshawl","html_url":"https://github.com/jshawl","followers_url":"https://api.github.com/users/jshawl/followers","following_url":"https://api.github.com/users/jshawl/following{/other_user}","gists_url":"https://api.github.com/users/jshawl/gists{/gist_id}","starred_url":"https://api.github.com/users/jshawl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jshawl/subscriptions","organizations_url":"https://api.github.com/users/jshawl/orgs","repos_url":"https://api.github.com/users/jshawl/repos","events_url":"https://api.github.com/users/jshawl/events{/privacy}","received_events_url":"https://api.github.com/users/jshawl/received_events","type":"User","site_admin":false},"body":"`alert( :( )`","created_at":"2015-07-16T00:14:50Z","updated_at":"2015-07-16T00:14:50Z","html_url":"https://github.com/ga-dc/atm/pull/1#discussion_r34744677","pull_request_url":"https://api.github.com/repos/ga-dc/atm/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/ga-dc/atm/pulls/comments/34744677"},"html":{"href":"https://github.com/ga-dc/atm/pull/1#discussion_r34744677"},"pull_request":{"href":"https://api.github.com/repos/ga-dc/atm/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/ga-dc/atm/pulls/1","id":39523969,"html_url":"https://github.com/ga-dc/atm/pull/1","diff_url":"https://github.com/ga-dc/atm/pull/1.diff","patch_url":"https://github.com/ga-dc/atm/pull/1.patch","issue_url":"https://api.github.com/repos/ga-dc/atm/issues/1","number":1,"state":"open","locked":false,"title":"Melissa - completed ATM assignment","user":{"login":"msteffan","id":7719096,"avatar_url":"https://avatars.githubusercontent.com/u/7719096?v=3","gravatar_id":"","url":"https://api.github.com/users/msteffan","html_url":"https://github.com/msteffan","followers_url":"https://api.github.com/users/msteffan/followers","following_url":"https://api.github.com/users/msteffan/following{/other_user}","gists_url":"https://api.github.com/users/msteffan/gists{/gist_id}","starred_url":"https://api.github.com/users/msteffan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msteffan/subscriptions","organizations_url":"https://api.github.com/users/msteffan/orgs","repos_url":"https://api.github.com/users/msteffan/repos","events_url":"https://api.github.com/users/msteffan/events{/privacy}","received_events_url":"https://api.github.com/users/msteffan/received_events","type":"User","site_admin":false},"body":"completeness: 5/5\r\ncomfort: 5/5\r\n\r\nI was able to finish the entire assignment, but would like to know how to combine the .text(), parseInt() & replace() methods all into one line of code. In this version, I had to split it up multiple variables, which achieved the desired result but is annoying.","created_at":"2015-07-08T21:12:42Z","updated_at":"2015-07-16T00:14:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a49d6b6fbe142499088417823d55730e4a3b58bc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ga-dc/atm/pulls/1/commits","review_comments_url":"https://api.github.com/repos/ga-dc/atm/pulls/1/comments","review_comment_url":"https://api.github.com/repos/ga-dc/atm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ga-dc/atm/issues/1/comments","statuses_url":"https://api.github.com/repos/ga-dc/atm/statuses/f1afcb67a94ee99edcdc40d6d667ba83174d6093","head":{"label":"msteffan:my_awesome_solution","ref":"my_awesome_solution","sha":"f1afcb67a94ee99edcdc40d6d667ba83174d6093","user":{"login":"msteffan","id":7719096,"avatar_url":"https://avatars.githubusercontent.com/u/7719096?v=3","gravatar_id":"","url":"https://api.github.com/users/msteffan","html_url":"https://github.com/msteffan","followers_url":"https://api.github.com/users/msteffan/followers","following_url":"https://api.github.com/users/msteffan/following{/other_user}","gists_url":"https://api.github.com/users/msteffan/gists{/gist_id}","starred_url":"https://api.github.com/users/msteffan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msteffan/subscriptions","organizations_url":"https://api.github.com/users/msteffan/orgs","repos_url":"https://api.github.com/users/msteffan/repos","events_url":"https://api.github.com/users/msteffan/events{/privacy}","received_events_url":"https://api.github.com/users/msteffan/received_events","type":"User","site_admin":false},"repo":{"id":38763449,"name":"atm","full_name":"msteffan/atm","owner":{"login":"msteffan","id":7719096,"avatar_url":"https://avatars.githubusercontent.com/u/7719096?v=3","gravatar_id":"","url":"https://api.github.com/users/msteffan","html_url":"https://github.com/msteffan","followers_url":"https://api.github.com/users/msteffan/followers","following_url":"https://api.github.com/users/msteffan/following{/other_user}","gists_url":"https://api.github.com/users/msteffan/gists{/gist_id}","starred_url":"https://api.github.com/users/msteffan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msteffan/subscriptions","organizations_url":"https://api.github.com/users/msteffan/orgs","repos_url":"https://api.github.com/users/msteffan/repos","events_url":"https://api.github.com/users/msteffan/events{/privacy}","received_events_url":"https://api.github.com/users/msteffan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/msteffan/atm","description":"[javascript, dom, html, css]","fork":true,"url":"https://api.github.com/repos/msteffan/atm","forks_url":"https://api.github.com/repos/msteffan/atm/forks","keys_url":"https://api.github.com/repos/msteffan/atm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/msteffan/atm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/msteffan/atm/teams","hooks_url":"https://api.github.com/repos/msteffan/atm/hooks","issue_events_url":"https://api.github.com/repos/msteffan/atm/issues/events{/number}","events_url":"https://api.github.com/repos/msteffan/atm/events","assignees_url":"https://api.github.com/repos/msteffan/atm/assignees{/user}","branches_url":"https://api.github.com/repos/msteffan/atm/branches{/branch}","tags_url":"https://api.github.com/repos/msteffan/atm/tags","blobs_url":"https://api.github.com/repos/msteffan/atm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/msteffan/atm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/msteffan/atm/git/refs{/sha}","trees_url":"https://api.github.com/repos/msteffan/atm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/msteffan/atm/statuses/{sha}","languages_url":"https://api.github.com/repos/msteffan/atm/languages","stargazers_url":"https://api.github.com/repos/msteffan/atm/stargazers","contributors_url":"https://api.github.com/repos/msteffan/atm/contributors","subscribers_url":"https://api.github.com/repos/msteffan/atm/subscribers","subscription_url":"https://api.github.com/repos/msteffan/atm/subscription","commits_url":"https://api.github.com/repos/msteffan/atm/commits{/sha}","git_commits_url":"https://api.github.com/repos/msteffan/atm/git/commits{/sha}","comments_url":"https://api.github.com/repos/msteffan/atm/comments{/number}","issue_comment_url":"https://api.github.com/repos/msteffan/atm/issues/comments{/number}","contents_url":"https://api.github.com/repos/msteffan/atm/contents/{+path}","compare_url":"https://api.github.com/repos/msteffan/atm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/msteffan/atm/merges","archive_url":"https://api.github.com/repos/msteffan/atm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/msteffan/atm/downloads","issues_url":"https://api.github.com/repos/msteffan/atm/issues{/number}","pulls_url":"https://api.github.com/repos/msteffan/atm/pulls{/number}","milestones_url":"https://api.github.com/repos/msteffan/atm/milestones{/number}","notifications_url":"https://api.github.com/repos/msteffan/atm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/msteffan/atm/labels{/name}","releases_url":"https://api.github.com/repos/msteffan/atm/releases{/id}","created_at":"2015-07-08T15:40:17Z","updated_at":"2015-07-08T20:40:29Z","pushed_at":"2015-07-09T00:01:07Z","git_url":"git://github.com/msteffan/atm.git","ssh_url":"git@github.com:msteffan/atm.git","clone_url":"https://github.com/msteffan/atm.git","svn_url":"https://github.com/msteffan/atm","homepage":null,"size":142,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ga-dc:master","ref":"master","sha":"dcd13e5ef5de05f3aad789d798ac2e7edf5b45a7","user":{"login":"ga-dc","id":10747017,"avatar_url":"https://avatars.githubusercontent.com/u/10747017?v=3","gravatar_id":"","url":"https://api.github.com/users/ga-dc","html_url":"https://github.com/ga-dc","followers_url":"https://api.github.com/users/ga-dc/followers","following_url":"https://api.github.com/users/ga-dc/following{/other_user}","gists_url":"https://api.github.com/users/ga-dc/gists{/gist_id}","starred_url":"https://api.github.com/users/ga-dc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ga-dc/subscriptions","organizations_url":"https://api.github.com/users/ga-dc/orgs","repos_url":"https://api.github.com/users/ga-dc/repos","events_url":"https://api.github.com/users/ga-dc/events{/privacy}","received_events_url":"https://api.github.com/users/ga-dc/received_events","type":"Organization","site_admin":false},"repo":{"id":37615907,"name":"atm","full_name":"ga-dc/atm","owner":{"login":"ga-dc","id":10747017,"avatar_url":"https://avatars.githubusercontent.com/u/10747017?v=3","gravatar_id":"","url":"https://api.github.com/users/ga-dc","html_url":"https://github.com/ga-dc","followers_url":"https://api.github.com/users/ga-dc/followers","following_url":"https://api.github.com/users/ga-dc/following{/other_user}","gists_url":"https://api.github.com/users/ga-dc/gists{/gist_id}","starred_url":"https://api.github.com/users/ga-dc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ga-dc/subscriptions","organizations_url":"https://api.github.com/users/ga-dc/orgs","repos_url":"https://api.github.com/users/ga-dc/repos","events_url":"https://api.github.com/users/ga-dc/events{/privacy}","received_events_url":"https://api.github.com/users/ga-dc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ga-dc/atm","description":"[javascript, dom, html, css]","fork":false,"url":"https://api.github.com/repos/ga-dc/atm","forks_url":"https://api.github.com/repos/ga-dc/atm/forks","keys_url":"https://api.github.com/repos/ga-dc/atm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ga-dc/atm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ga-dc/atm/teams","hooks_url":"https://api.github.com/repos/ga-dc/atm/hooks","issue_events_url":"https://api.github.com/repos/ga-dc/atm/issues/events{/number}","events_url":"https://api.github.com/repos/ga-dc/atm/events","assignees_url":"https://api.github.com/repos/ga-dc/atm/assignees{/user}","branches_url":"https://api.github.com/repos/ga-dc/atm/branches{/branch}","tags_url":"https://api.github.com/repos/ga-dc/atm/tags","blobs_url":"https://api.github.com/repos/ga-dc/atm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ga-dc/atm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ga-dc/atm/git/refs{/sha}","trees_url":"https://api.github.com/repos/ga-dc/atm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ga-dc/atm/statuses/{sha}","languages_url":"https://api.github.com/repos/ga-dc/atm/languages","stargazers_url":"https://api.github.com/repos/ga-dc/atm/stargazers","contributors_url":"https://api.github.com/repos/ga-dc/atm/contributors","subscribers_url":"https://api.github.com/repos/ga-dc/atm/subscribers","subscription_url":"https://api.github.com/repos/ga-dc/atm/subscription","commits_url":"https://api.github.com/repos/ga-dc/atm/commits{/sha}","git_commits_url":"https://api.github.com/repos/ga-dc/atm/git/commits{/sha}","comments_url":"https://api.github.com/repos/ga-dc/atm/comments{/number}","issue_comment_url":"https://api.github.com/repos/ga-dc/atm/issues/comments{/number}","contents_url":"https://api.github.com/repos/ga-dc/atm/contents/{+path}","compare_url":"https://api.github.com/repos/ga-dc/atm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ga-dc/atm/merges","archive_url":"https://api.github.com/repos/ga-dc/atm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ga-dc/atm/downloads","issues_url":"https://api.github.com/repos/ga-dc/atm/issues{/number}","pulls_url":"https://api.github.com/repos/ga-dc/atm/pulls{/number}","milestones_url":"https://api.github.com/repos/ga-dc/atm/milestones{/number}","notifications_url":"https://api.github.com/repos/ga-dc/atm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ga-dc/atm/labels{/name}","releases_url":"https://api.github.com/repos/ga-dc/atm/releases{/id}","created_at":"2015-06-17T19:21:59Z","updated_at":"2015-07-08T13:35:57Z","pushed_at":"2015-07-13T12:49:17Z","git_url":"git://github.com/ga-dc/atm.git","ssh_url":"git@github.com:ga-dc/atm.git","clone_url":"https://github.com/ga-dc/atm.git","svn_url":"https://github.com/ga-dc/atm","homepage":null,"size":1656,"stargazers_count":1,"watchers_count":1,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":50,"mirror_url":null,"open_issues_count":6,"forks":50,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ga-dc/atm/pulls/1"},"html":{"href":"https://github.com/ga-dc/atm/pull/1"},"issue":{"href":"https://api.github.com/repos/ga-dc/atm/issues/1"},"comments":{"href":"https://api.github.com/repos/ga-dc/atm/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/ga-dc/atm/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/ga-dc/atm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ga-dc/atm/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/ga-dc/atm/statuses/f1afcb67a94ee99edcdc40d6d667ba83174d6093"}}}}