I'm new to JavaScript (and programming in general). I was just playing around with this script that checks how many combat rounds it takes for fighter1 to knock out fighter2 and writes out all the combat events to the page.
When I call the fightClub(); function from my HTML-file, all that gets printed is "Test". How can I get this to work? Is my logic flawed?
Any help would be much appreciated! <3
const fighter1 = array ("Jimmy", 10, 2);
const fighter2 = array ("Chet", 10, 2);
function fightClub(fighter1, fighter2){
document.write('Test');
let hitcheck = math.ceil(math.random() * 10);
while (fighter2[1] > 0){
let roundNumber = 1;
roundNumber++;
if(hitcheck >= 5){
fighter2[1] = fighter2[1] - fighter1[2];
document.write('Round' + roundNumber);
document.write(fighter1[0] + ' deals ' + fighter1[2] + ' damage to ' + fighter2[0]);
}else {
document.write('Round' + roundNumber);
document.write(fighter1[0] + ' swung in the air and... missed ' + fighter2[0]);
}
if(fighter2[1] <= 0){
document.write(fighter2[0] + ' was knocked out.');
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire