We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I am programming an interactive sketch in JavaScript mode. It will display a map.
Basically, the sketch will have a few buttons and according to the one pressed, there will be changes on the map, mostly colors and text.
I don't know how to deal with the way to organize the code according to the choice. My purpose is to keep the code efficient, lightweight (must be loaded on a Web page) and easy to modify.
I am thinking either to use switch/case everytime the code should be different according to the button pressed or to use functions with an int corresponding to the chosen button passed as argument.
What would you do ?
Thank you in advance.
Answers
This question might be too general to really get an answer, but yes, you generally use if statements or switch statements for conditional execution.
You might consider breaking your code up into multiple methods as well. That way your if or switch statements can simply call a method instead of containing large chunks of code.
Some Wikipedia articles about programming paradigms:
https://en.wikipedia.org/wiki/Structured_programming
https://en.wikipedia.org/wiki/Procedural_programming