Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
Javascript: How to input, store, and output values (banking app)

I'm working through a course on JavaScript currently and honestly I'm having a pretty difficult time with it. If anyone has any resources they could recommend for learning, I'd appreciate it!

I'm trying to make a simple banking app with these requirements:

  1. The user should see a prompt so they can type which action to perform.
  2. The user will have a list of 4 actions to choose from:
    • Q to quit (immediately quits the program).
    • W to withdraw. The user will be prompted again to enter an amount to withdraw.
    • D to deposit. The user will be prompted again to enter an amount to deposit.
    • B to view balance. The user will see their balance.
  3. The balance should update after any withdrawal or deposit transactions.
  4. The program will loop asking for input until the user enters Q.

Here's my basic HTML for a very simple site

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <h1>Welcome!</h1>
    <button onclick="start()">Click here to get started.</button>
    <script src="scripts.js"></script>
  </body>
</html>

And here's as far as I've been able to get with the JS...

function start() {
  let input = prompt('What would you like to do?');

  if input = 'w' {
    alert('Withdraw');
  } else () {

  }
}

And I know that's probably not even the direction I need to be going. I'm honestly stuck because I don't really know where to start. Any and all advice is much appreciated, TIA!!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Regarding resources, you can basically use any recorded or written tutorial. I also like code challenges. To learn while you code, go step by step and use Google :) As you may have done for "get user input javascript".

You have already collected some user input. Try to reuse this for the other things a user can do. Run calculations based on the value the user enters. Finally, record and store the balance.

At a later point, when you learned the new concepts, you can even try persisting the balances using a database, cookie, or web storage.

In the following example (thanks to ruleboy21) the user can enter actions in any order. There is no check yet if there's enough money left, etc.

Play around with this code to learn:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <h1>Banking app</h1>
    <p>Click the button below to start the app. Options: (w)ithdraw, (d)eposit, (b)alance, (q)uit</p>
    <button onclick="start()">Click here to get started.</button>

    <script type="text/javascript">
        let balance = 0;

        function start() {
            let input = prompt('What would you like to do?');
                        
            // debug output for testing
            // Open the inspector to see user input
            // console.log(input);

            if (input == 'q' || input == "") { // Enter quits as well.
                return;
            } else if (input == 'w') {
                withdraw(); // see functions below
            } else if (input == 'd') {
                deposit();
            } else if (input == 'b') { 
                showBalance();
            } else {
                alert('Unsupported action: use (w)ithdraw, (d)eposit, or (b)alance. Press q or enter to quit');
            }
            start(); // restarts the app after action
        }
        
         function deposit() {
            let amount = prompt('Enter an amount to deposit');
            amount = isNaN(amount) ? 0 : parseFloat(amount);
            balance += amount;
            return balance;
         }
         
         function showBalance() {
            alert('Current balance: '+balance);
         }

        function withdraw() {
            let amount = prompt('Enter an amount to withdraw');
            amount = isNaN(amount) ? 0 : parseFloat(amount);
            balance = balance - amount;
            return balance;
         }
         
    </script>
</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda