_scripts/withdraw.js
// Validates that it is a number and you will not overdraft
Validates that it is a number and you will not overdraft
Validates that it is a number and you will not overdraft
function withdrawMoney() {
		if (!isNaN(withdraw) && withdraw > 0 && withdraw <= balance) {
			let newBalance = Number(balance) - Number(withdraw);
			console.log(Number(newBalance));
			let tracker = false;
      		setBalance(newBalance);
      		setStatus(`$${withdraw} retirados de la cuenta.`);
      		setWithdraw('');
			for (const {email, password, balance} of ctx.users) {
				console.log(`Checking ${currentemail} ${currentpass} against ${email} ${password}`);
				if (currentemail == email && currentpass == password) {
					console.log(`${currentemail} ${currentpass} is correct`);
					for (var i=0, length=ctx.users.length; i<length; i++) {
						if (ctx.users[i].email == currentemail) {
							console.log(`Checking ${email}`)
							ctx.users[i].balance = Number(newBalance);
							tracker = true;
						}
					}
				}
			}
			if (tracker) {
				setStatus(`$${withdraw} retirados de la cuenta.`);
				setTimeout(() => setStatus(''), 5000);
				setWithdraw('');
				setBalance(Number(newBalance))
			}
		} else if (withdraw > balance) {
			setStatus(`Error: No puede retirar mas de lo que tiene en su balance $${balance}. Intente denuevo.`);
			setWithdraw('');
			setTimeout(() => setStatus(''), 5000);
		} else if (!isNaN(withdraw)) {
			setStatus('Error: El monto de retiro debe ser mayor a $0.00. Intente denuevo.');
			setWithdraw('');
			setTimeout(() => setStatus(''), 5000);
		} else {
			setStatus('Error: El retiro debe ser un numero. Intente denuevo.');
			setWithdraw('');
			setTimeout(() => setStatus(''), 5000);
		}
		return;
	}
function withdrawMoney ( ) { if ( ! isNaN ( withdraw ) && withdraw > 0 && withdraw <= balance ) { let newBalance = Number ( balance ) - Number ( withdraw ) ; console . log ( Number ( newBalance ) ) ; let tracker = false ; setBalance ( newBalance ) ; setStatus ( ` ${ withdraw } ` ) ; setWithdraw ( '' ) ; for ( const { email , password , balance } of ctx . users ) { console . log ( ` ${ currentemail } ${ currentpass } ${ email } ${ password } ` ) ; if ( currentemail == email && currentpass == password ) { console . log ( ` ${ currentemail } ${ currentpass } ` ) ; for ( var i = 0 , length = ctx . users . length ; i < length ; i ++ ) { if ( ctx . users [ i ] . email == currentemail ) { console . log ( ` ${ email } ` ) ctx . users [ i ] . balance = Number ( newBalance ) ; tracker = true ; } } } } if ( tracker ) { setStatus ( ` ${ withdraw } ` ) ; setTimeout ( ( ) => setStatus ( '' ) , 5000 ) ; setWithdraw ( '' ) ; setBalance ( Number ( newBalance ) ) } } else if ( withdraw > balance ) { setStatus ( ` ${ balance } ` ) ; setWithdraw ( '' ) ; setTimeout ( ( ) => setStatus ( '' ) , 5000 ) ; } else if ( ! isNaN ( withdraw ) ) { setStatus ( 'Error: El monto de retiro debe ser mayor a $0.00. Intente denuevo.' ) ; setWithdraw ( '' ) ; setTimeout ( ( ) => setStatus ( '' ) , 5000 ) ; } else { setStatus ( 'Error: El retiro debe ser un numero. Intente denuevo.' ) ; setWithdraw ( '' ) ; setTimeout ( ( ) => setStatus ( '' ) , 5000 ) ; } return ; }
Validates that it is a number and you will not overdraft
Validates that it is a number and you will not overdraft
//Check if the username or passwords match anyone is the database //Making all changes to state