Skip to content
Advertisement

How do I change the function of a button more than 2 times?

I would like to make one button do 3 or more things one after the other. I’m trying to make a CYOA and I need one button to go through multiple layers/phases/sections(Start to layer 1 to layer 2) of the CYOA, with as little repeating code* as possible. I have placeholder text in the areas where the text in the title and the buttons go to see that the code runs properly

*Example of repeating code

JavaScript

HTML

JavaScript

Javascript

JavaScript

Advertisement

Answer

If you want to do it with ifs, you just need one function and update a variable.

JavaScript

Problem with that is you have a lot of repeated code. I would use an array of objects.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement