What type of topic is this?
Discussion | Support | Bug Report
Motoko code:
import Debug "mo:base/Debug";
import Time "mo:base/Time";
import Float "mo:base/Float";
actor DBank {
stable var currentValue : Float = 300;
currentValue := 300;
Debug.print(debug_show (currentValue));
stable var startTime = Time.now();
startTime := Time.now();
Debug.print(debug_show (startTime));
let id = 2348923840928349;
// Debug.print(debug_show(id));
public func topUp(amount : Float) {
currentValue += amount;
Debug.print(debug_show (currentValue));
};
public func withdraw(amount : Float) {
let tempValue : Float = currentValue - amount;
if (tempValue >= 0) {
currentValue -= amount;
Debug.print(debug_show (currentValue));
} else {
Debug.print("Amount too large, currentValue less than zero.");
};
};
public query func checkBalance() : async Float {
return currentValue;
};
// topUp();
public func compound() {
let currentTime = Time.now();
let timeElapsedNS = currentTime - startTime;
let timeElapsedS = timeElapsedNS / 1000000000;
currentValue := currentValue * (1.01 ** Float.fromInt(timeElapsedS));
startTime := currentTime;
};
};
javascript code:
import {dbank} from "../../declarations/dbank";
window.addEventListener("load", async function() {
const currentAmount= await dbank.checkBalance();
console.log(response); // Log the response
document.getElementById("value").innerText=Math.rount = (currentAmount*100)/100;
});
document.querySelector("form").addEventListener("submit",async function(event){
console.log("Submit button clicked");
const inputAmount = parseFloat(document.getElementById("input-amount").value);
const outputAmount = parseFloat(document.getElementById("withdrawl-amount").value);
await dbank.topUp(inputAmount);
const currentAmount= await dbank.checkBalance();
document.getElementById("value").innerText=Math.rount = (currentAmount*100)/100;
});