Ad
  • Custom User Avatar

    that really helped clear it up. thanks Chrono!

  • Custom User Avatar

    these are the objects listed in the console.

    Fighter {
    name: 'Cuban',
    health: -60,
    damagePerAttack: 47,
    toString: [Function] }
    Fighter {
    name: 'Mark',
    health: -29,
    damagePerAttack: 97,
    toString: [Function] }

  • Custom User Avatar

    my code is failing due to two or three of the random tests under the attempt portion, both fighters will start out with negative health. Not sure how to proceed and i really want to finish this one.

    in JS

    function declareWinner(fighter1, fighter2, firstAttacker) {
    let hitC1 = 0;

    function whoWon(){
    if(fighter1.health > 0){
    return fighter1.name;
    }
    else {
    return fighter2.name;
    }
    }

    function secondRound(){
    if(fighter1.health > 0 && fighter2.health > 0){
    do {
    if(hitC1 > 0){
    fighter1.health = fighter1.health - fighter2.damagePerAttack;
    fighter2.health = fighter2.health - fighter1.damagePerAttack;
    }
    else {
    fighter2.health = fighter2.health - fighter1.damagePerAttack;
    fighter1.health = fighter1.health - fighter2.damagePerAttack;
    }
    }
    while (fighter1.health > 0 && fighter2.health > 0)
    }
    else{
    whoWon();
    }
    }
    /below decides first attack/
    function fightOn(){
    do {
    if (firstAttacker === fighter1.name){
    fighter2.health = fighter2.health - fighter1.damagePerAttack;
    hitC1++;
    secondRound();
    break;
    }
    else if(firstAttacker === fighter2.name){
    fighter1.health = fighter1.health - fighter2.damagePerAttack;
    secondRound();
    break;
    }
    }
    while(fighter1.health > 0 && fighter2.health > 0)
    }
    /below returns outcome of fight/
    fightOn();
    return whoWon();
    }