Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda