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

248
Visualizações
How do I make it so when my array includes a specific word a text input shows up?

After getting help countless times in this forum, I finally created my own account after getting stuck in my code, and not being able to resolve it :(

Pre-info, I wanted to create a text adventure with javascript and followed this guide on youtube: https://www.youtube.com/watch?v=R1S_NhKkvGA&ab_channel=WebDevSimplified

I wanted my game to have several "rooms" that you can go thru, and some rooms you only can go thru if you have found a key for example. See demo. To do this i added if/if else at the end of my selectChoice.

However, If you watch the demo, I want so that when you press the button that says 'Go to Bowser's door(!!!)', a text input shows up, instead of the button that says Enter favorite song. The user is then supposed to enter a guess of Bowsers favorite song and if it's right they go to the next textNode (the one that now appears after pressing 'Enter favorite song'. If it's wrong I want a new text to show up and the option to go back to the previous room/textNode.

TLDR; I want it so that when i have a specific word in my array such as showInput: '(text that shows up on a label before text input)', a text input shows up for the user. Where if the user enters the right answer, the user gets sent to the next "id" in my array. See demo to visualise.

In conclusion, I cant seem to find the solution to implementing this function. Some help would be super appreciated.

If I missed any important information or have to explain my code, just let me know! This is my first post on stackoverflow :)

Here's the demo so far: https://willen17.github.io/Textspel/ Here's my files and code: https://github.com/Willen17/Textspel

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

0

This is an open ended question, but I'll try and help out. There are a few options for you, you can:

  1. create an <input /> tag and grab data from it (you'll probably want to use a form with something like onsubmit or a key listener) https://developer.mozilla.org/en-US/docs/Learn/Forms

  2. you can show a pop up called a prompt that asks the user for input. https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt

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