Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!