Hey

I'm new here, and to programming in general (working my way through Codecademy and TTH), and I was just wondering if someone could help me out with some code. I'm trying to make a basic game, where the user and the computer have 20 life, and each round the user can either attack or attempt to run, and basically whoever runs out of life first is the loser.

It loops through the first round just fine, and then when round two comes along, it computes the userAttack damage, but then displays an error and ends the game.

Here is the code:

Code:
var userHealth = 20;
var compHealth = 20;
var userAttack = 0;
var compAttack = 0;
var userRun = 0;
var compRun = 0;
var userChoice = "";

for (i=2; i<3; i++){
	console.log("Your Health:"+" "+userHealth);
	console.log("Comp Health:"+" "+compHealth);
	var userChoice = prompt("Would you like to ATTACK or RUN?").toLowerCase();
	switch(userChoice) {
		case "attack":
			var userAttack = Math.floor(Math.random() * 10);
			var compAttack = Math.floor(Math.random() * 10);
			alert("You did"+" "+userAttack+" "+"damage!");
			alert("You took"+" "+compAttack+" "+"damage!");
			var userHealth = userHealth - compAttack;
			var compHealth = compHealth - userAttack;
			alert("Your life:"+" "+userHealth+". Comp life:"+" "+compHealth+".");
			break;
		case "run":
			var userRun = Math.random() * 5;
			var compRun = Math.random() * 4;
			if (userRun > compRun) {
				alert("You got away!");
				alert("Game over!");
			} else {
				alert("You tried to run but couldn't get away!");
				compAttack = Math.floor(Math.random() * 10);
				userHealth = userHealth - compAttack;
				alert("You were shot while running and took"+" "+compAttack+" "+"damage!");
			}
			break;
		default:
			alert("You didn't pick 'attack' or 'run'. Please try again!");
	}
				if (userHealth <= 0 && compHealth > 0) {
				alert("Game over dude! Game over!");
			} else if (userHealth > 0 && compHealth <=0) {
				alert("You won!");
				alert("You didn't win ****! But you won!");
			} else if (userHealth < 1 && compHealth < 1) {
				alert("You killed each other!");
				alert("So technically since you're dead, you lost!");
				alert("Play better next time n00b!");
			} else {
				i = 1;
			}
}
The error it displays is:

Code:
[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.alert]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: http://www.codecademy.com/assets/repl.html :: <TOP_LEVEL> :: line 18"  data: no]
All I know is that line 18 is the one which determines compAttack, and thats where it displays the error during the second round.

Any help on this would be greatly appreciated by a programming noob

Also, any recommendations or suggestions relating to the code would be great, particularly on the loop. I couldn't figure out how to make the game last more than a single round, so I did the (i=2;i<3;i++) loop with the "i = 1" (no quotes) coming into effect only if both User and Comp have at least 1 life (I figure the "i = 1" allows the loop to go back to the beginning and become "i = 2" again, and if someone wins it will automatically become "i = 3" and close the loop to end the game.

Thanks a bunch for any and all advice. I'm looking forward to continuously adding on to this while I finish out my Javascript track at Codecademy, with my current javascript goal being to make a game similar to the already existing "Drug Wars" game.