Help with a passion project - 'Dragon Slayer' my javascript rpg!

Hey everyone! I’ve only been coding for a month or so, but I’m loving it! I’m most of the way through the Javascript section and took a break to practice on my own. I’ve made a [very basic] text based rpg with what I’ve learned.

I could use a little help, I’m sure this could’ve been coded with way less lines, what can I do next time to cut down on repeating myself?

Also, I am stuck on one aspect. After a fighting turn I ask my user if they want to continue fighting or run away with a prompt (line 116 for example). Right now I can’t for the life of me make the function stop looping even if they do enter “run” How could I do this?

Thanks for all the support and keep coding!

you could create one fight function

  if (ènemy> 0 && playerHp > 0) {``

and rather than hard coding each with orik or troll take the name from the button click and assign to a variable and pass it into the function eg var enemy = value of which button gets clicked
as for looping error not sure yet ... it quit first time i typed run but not next ... i would have to go in to devtools in chrome to try and debug but unfortunately late now over here and im shutting down for the night ... might get a chance tomorrow to look if you havent got help or sorted

Thank you John, your input is greatly appreciated :slight_smile:

do post back if you mange to replace those functions with just the one … or if you dont post again … i get very busy with my studying but i like to help out if i can especially when the person im trying to help wants to learn, we all hit roadblocks and run into things that we dont quite understand at the point we are at in our learning … so keep plugging away … sometimes though you need to remember to step away for a day come back and look at it again … and you will find on occasion , not all the time … that things are clearer a make more sense and you then progress pass that stumbling block.

I had that realization the other day actually. I was getting flustered with things, but I took a day off and came back to it with a clear head.

I intend to go back to my waypoint lessons, consolidate my knowledge a little bit and then come back to this project with your suggestions in mind. I’ll greatly appreciate your assistance when I hit the next stumbling block!

1 Like