javascript role playing game

Hi all. I'm writing my first javascript game. It's a role playing game where the user fights an Ogre, and not elaborate at all. I'd like the game to end when the Ogre's life is at zero OR the users life is at zero. I can't figure out how to have the program keep track of the amount of damage the user and the Ogre inflict on each other. Any ideas? Also, if this has been asked before, please point me in the direction of the completed discussion and I'll look it up there. Thanks.

Could you simply subtract the damage from orgelife in your stabing() and punching() function when the player successfully attack the orge (line 36 & line 48)? Unless you are talking about 1-hit KO thing (which is what you are doing right now).

That's what I'd like to do, subtract from both based on the hp lost but I can't figure out how to do it. I figured out how to fix the players life, and the game now ends when life >= 0, but I can't get the other part to work.

By the way (because I can't go back to edit my post), the sample above is NOT the best both presentation and algorithm. I simply modified from yours in order to demonstrate how it would be when it is working. There are flaws in many places that can be improved.

1)Mathematics of this game doesn't make much sense. You could refine it later.
2)The monster data could be read from somewhere else in an object rather than declare as global.
3)Your character could be declare in an object.
4)The command in switch statement does not show anything else if you enter something rather than what it is allowed: stab, punch, or run.
5)The running() function should return true or false, so that the ogremove() could be called later in the switch statement instead of being called inside the running() function.

The game, and my site, is more of an attempt to get good at programming than anything else. This particular game is practice with Math.random and Math.floor as they relate to decision making, versus just giving out a number. I wanted everything to be random, with a ceiling, because the amount of damage you would inflict on anything is unpredictable until you have struck it but there is a ceiling to the amount of damage an action can inflict.

As I barely know what I'm doing, I totally appreciate your comments and feedback and will keep them in mind. It's much better to read your last comment, than just the correction to the code.

Hmm... You have more logic into this, but not really enough.. It is my fault for going too fast on you and not explaning enough. Here is my take on this...

It is good to keep practicing and use different built-in function, so that one could understand the language better. A good program may not need to be complex. Cooperating game into programming could be fun. You are on the right track. The only thing you need to keep in mind is that a good program is not easy to defined especially for a beginner. The reason is that the design of a program requires knowledge and experience. These requirements do not come in a short period of time and may not be taught. The implementation, unlike design, is trivia and easily taught (this includes naming convention for functions & vairable).

1)You could still use global values for ogrelife & player life. It is, however, a one time use for a single run. When I said that you could read the value from else where or object, I mean you could copy/get the value later.
2)You could use the 'default' in switch statement to handle all other cases that do not match whatever condition you want it to be.
3)Your current implementation puts the ogre life values inside and it becomes a local variables. This would not really work but rather create an infinite loop. You need to read about variable scope for JavaScript only (the language now has slightly different scope definition compared to other stable & standard languages).
4)Why are you setting the window.location.href in your script?
5)Below is a simple script consists of start(), stab(), punch(), run(), ogreAttack(), displayCurrentLifePoints(). It contains enough comment and hope it would be easy for you to understand. It should provide a simple but cover all functionalities (including display).

Wow, thanks for the explanation and the code. This is exactly what I'm trying to accomplish and am thankful I'm at least on the right track. I'm going to do more reading and then I'll revisist and rewrite the game. When I've redone it, I'll compare it to yours. Thanks again.