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

154
Visualizações
Map Directions HTML and JS

I am trying to make a map of a mall with this script:

<!DOCTYPE html>
<html>

<head>
  <title>Display Message</title>
  <script>
    // (B) CONFIRM
    function demoA() {
      let sgl = 'Target';
      sgl;
      var destination1 = prompt("Enter Your Destination", " ");
      if (destination1 = sgl) {
        return true
        var location2 = prompt("Enter Your Closest Store", " ")
        alert("Starting Directions to " + destination1)
      } else {
        return false
      }
    }
  </script>
</head>

<body>
  <!-- (D) TEST BUTTONS -->
  <input type="button" value="Directions" onclick="demoA()" />
</body>

</html>

But, when I run this, for the destination1 var, I put Target but it doesn't ask me my closest store. Another problem is I am trying to use a string of the name of the stores but I can't get it to work.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Condition should be

if (destination1 === sgl) 

and not

if (destination1 = sgl) 

Also after this line you have:

    return true

And your function done with execution there (wont reach next line)

about 4 years ago · Juan Pablo Isaza Relatório

0

You are returning from the function before calling prompt a second time here:

      let sgl = 'Target';
      sgl;
      var destination1 = prompt("Enter Your Destination", " ");
      if (destination1 === sgl) {
        return true // this returns from the function and no following code is run
        var location2 = prompt("Enter Your Closest Store", " ") // never runs
        alert("Starting Directions to "+destination1) // never runs
        // put your return here to run the above
      } else {
        return false
      }
    }
about 4 years ago · Juan Pablo Isaza Relatório

0

Edit: Good News! I got it to work thanks to @munleashed and @Tom! Here is the new code for those who would need it!

<!DOCTYPE html>
<html>
  <head>
    <title>Display Message</title>
    <script>
    // (B) CONFIRM
    function demoA () {
      let sgl = 'Target';
      sgl;
      var destination1 = prompt("Enter Your Destination", " ");
      if (destination1 === sgl) {
        var location2 = prompt("Enter Your Closest Store", " ") // never runs
        alert("Starting Directions to "+destination1) // never runs
        return true
        // put your return here to run the above
      } else {
        return false
      }
    }
    </script>
  </head>
  <body>
    <!-- (D) TEST BUTTONS -->
    <input type="button" value="Directions" onclick="demoA()"/>
  </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