E
E
Electro-max2022-04-01 15:33:10
JavaScript
Electro-max, 2022-04-01 15:33:10

How to simplify JS code?

I study JS in practice of creating a combat system for the game. Already at the start of the combat, I encountered code duplication. So far everything is working quickly, but there will be problems further. I guess that all the checks through which I interact with the player can be put into arrays and get the desired press through cycles, but I still don’t understand how this is done. According to the game that I draw: at the bottom there are 5 heroes in a row, in the upper left corner there is a pet that throws magical amplifications, by clicking on the pet, magic opens, activate any magic and click on the hero. The hero will have the selected power-up.
https://codepen.io/Electromax/pen/QWaqbRe

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voproser45654, 2022-04-01
@Electro-max

Variables can be written

let a
let b
let c
and let a, b, cinstead of if use switch case. This will greatly shorten your code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question