+ 1
Help with text based game (Javascript)
Hello. I'm creating a text-based game with JavaScript, and my knowledge is limited. The idea is to create a branching storyline with different "choices and endings" depending on the options chosen. However, I'm not sure how to proceed without using external links to other web pages to display the results of those choices. I know it's possible, but I'm not sure if it can be done using the same HTML page with JavaScript, which is what I'm interested in. If anyone can help me, I would greatly appreciate it. Thank you. This is the code: https://www.sololearn.com/compiler-playground/WCi6CoD1wmLf
5 Respuestas
+ 2
I think you want something like this
https://code.sololearn.com/We8Jvl3Jw74w/?ref=app
+ 1
Here are the main issues with the original code:
Duplicate Function Declarations: There were duplicate declarations of the mostrarOpciones function, which could lead to confusion and potential issues. It's essential to have a single, well-defined function for this purpose.
Missing IDs for Options: In the original code, the list items (options) were missing id attributes, which are necessary for attaching event listeners and identifying which option the player selects.
No Game Logic: The code didn't have any game logic beyond displaying messages. To create a branching storyline with different outcomes and consequences, you need to keep track of the player's progress and use conditional statements to handle different scenarios based on their choices.
I fixed the code, I put the comments for help: https://www.sololearn.com/compiler-playground/WE5fD1OdVbq8
+ 1
@gaurrions You too!
0
Coderwe2
Thank you very much for helping me. As I mentioned in the comment above, I don't have much knowledge of JavaScript, so I appreciate the explanation and will keep it in mind for this code and others in the future.
By the way, there is an issue with the code you edited, as it doesn't allow me to open it in the Sololearn code playground(App). I'll try to copy the link address and paste it in the PC browser to see if that works.
0
Coderwe2 Well,now I can see the code published un your profile so there is no problem with that.Have a nice day :)