Help with text based game (Javascript) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

22nd Oct 2023, 9:30 PM
guarrions
guarrions - avatar
5 Answers
+ 2
I think you want something like this https://code.sololearn.com/We8Jvl3Jw74w/?ref=app
22nd Oct 2023, 10:46 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
+ 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
23rd Oct 2023, 11:00 AM
Coderwe2
Coderwe2 - avatar
+ 1
@gaurrions You too!
23rd Oct 2023, 11:48 AM
Coderwe2
Coderwe2 - avatar
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.
23rd Oct 2023, 11:44 AM
guarrions
guarrions - avatar
0
Coderwe2 Well,now I can see the code published un your profile so there is no problem with that.Have a nice day :)
23rd Oct 2023, 11:47 AM
guarrions
guarrions - avatar