CreateAccount(name, accountNumber, password) {
this.name = name;
this.accountNumber = accountNumber;
this.balance = 0;
this.password = password;
}
CreateAccount.prototype.deposit = function(pass, amount) {
if (this.password === pass) {
this.balance += amount;
} else throw new Error("Wrong password");
};
function display(objorclass, element, balance) {
const elem = document.querySelector(`${objorclass}${element}`);
elem.innerHTML = `${balance}`;
}
function check() {
document.querySelector("#deposit").addEventListener("click", () => {
const pass = document.querySelector("#pass").value;
const amount = document.querySelector("#am").value;
const fixedAmmount = Number(amount);
account1.deposit(pass, fixedAmmount);
display("#", "amount", `${account1.balance} <br>${account1.name}`);
});
}
const account1 = new CreateAccount("simon", "01", "password");
check();
It looks like you posted long piece of code, consider editing it out and putting it on hastebin.com and pasting link to it instead. Alternatively, send your code in a file.
for the id selectors you can use getElementById
turns the check function into an IIFE
^
can i stick this in one function and use curry to apply them all ?
Seems pretty class based
const thr = msg => { throw new Error(msg); }; const Account = (name, accountNubmer, password) => ({ name, accountNumber, balance: 0, password }); const deposit = (account, amount, pass) => account.password === pass ? ({ ...account, balance: balance + amount }) : thr('Wrong password');
Обсуждают сегодня