# How to use JavaScript i have this code but i don't know how to use it

**URL:** <https://community.glideapps.com/t/how-to-use-javascript-i-have-this-code-but-i-dont-know-how-to-use-it/75856>\
**Category:** Ask for Help\
**Created:** [August 25, 2024, 11:13am UTC](https://community.glideapps.com/t/how-to-use-javascript-i-have-this-code-but-i-dont-know-how-to-use-it/75856 "2024-08-25T11:13:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TTC56010](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@TTC56010](https://community.glideapps.com/u/TTC56010)\
**Post date:** [August 25, 2024, 11:13am UTC](https://community.glideapps.com/t/how-to-use-javascript-i-have-this-code-but-i-dont-know-how-to-use-it/75856/1 "2024-08-25T11:13:15Z")

</div>

// ฟังก์ชันคำนวณยอดเงินคงเหลือ  
function calculateBalance(deposit, withdraw, previousBalance) {  
return previousBalance + deposit - withdraw;  
}

// ฟังก์ชันที่เรียกใช้งาน  
function processTransaction(transaction) {  
const deposit = transaction.deposit || 0;  
const withdraw = transaction.withdraw || 0;  
const previousBalance = transaction.previousBalance || 0;

const newBalance = calculateBalance(deposit, withdraw, previousBalance);

return {  
…transaction,  
balance: newBalance  
};  
}

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 25, 2024, 1:07pm UTC](https://community.glideapps.com/t/how-to-use-javascript-i-have-this-code-but-i-dont-know-how-to-use-it/75856/2 "2024-08-25T13:07:42Z")

</div>

If this is related to your previous post, please review this video again.

> [@How to make column 2 - column 3 = column 4](https://community.glideapps.com/t/how-to-make-column-2-column-3-column-4/75839/6):
>
> You can use a Query column. The below video shows the general technique: [https://www.loom.com/share/042be3be13004355b0dedec1be67b400](https://www.loom.com/share/042be3be13004355b0dedec1be67b400)
