Here's my test-battle:var user;
var alien = 100;
var playerHp = 100;
var gatlingGun = Math.floor(Math.random() * 20) + 1;
var missile = Math.floor(Math.random() * 100)+ 20;
var noMissiles = 4;
var gameStart = function(){
var opening = alert("You're in your giant robot, preparing to battle large space aliens.\nYou launch out of the massive spacecraft and your whole squadron is\n engaged in combat.");
var opening2 = alert("You spot a target approaching at a high speed,\n twelve o' clock ");
}
var playerTurn = function(){
user = prompt("You have three options: type 'gg' for 'Gatling guns', 'm' for 'fire missile', or 'r' for 'retreat'").toUpperCase();
switch(user) {
case 'GG':
var hit = Math.random();
if(hit>0.10){
var damage = Math.floor(Math.random() * 25) + 5;
alien -= damage;
if(alien<=0){
console.log("Target destroyed!")
} else {
console.log("Direct hit! Enemy is down " + damage + "hp!");
}
} else {
console.log("Target missed!");
};
break;
case 'M':
var hit = Math.random();
noMissiles -= 1;
if(noMissiles<=0){
console.log("Out of ammo!");
} else {
if(hit>0.10){
var mdamage = Math.floor(Math.random() * 60) + 20;
alien -= mdamage;
if(alien<=0){
console.log("Target destroyed!")
} else {
console.log("Direct hit! Enemy is down " + mdamage + "hp!");
}
} else {
console.log("Target missed!");
};
};
break;
case 'R':
console.log("You've gained some distance, but the enemy is still approaching!");
break;
default:
console.log("Test");
}
};
var enemyTurn = function(){
var hit = Math.random();
if(hit>=0.40){
var damage = Math.floor(Math.random() * 25) + 5;
playerHp -= damage;
if(playerHp<=0){
console.log("Game Over!");
} else {
console.log("You've been hit! " + playerHp + "/100 Shields remaining!");
}
} else {
console.log("You've evaded the enemy's attack!");
}
};
var play = function(){
gameStart();
while(playerHp>0&&alien>0){
playerTurn();
if(alien>0){
alert("The enemy is attacking!");
enemyTurn();
}
}
alert("The game is over.");
};