Ad
  • Custom User Avatar

    that really helped clear it up. thanks Chrono!

  • Custom User Avatar

    You had your console.logs inside whoWonput them at the start of declareWinner and you'll see the starting health of the fighters is never < 1.

  • 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

    both fighters will start out with negative health

    That's not true, you're printing the data after several rounds.

    Death is defined as having health <= 0.

    A dead fighter can't attack another. So there is always one winner.

  • 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();
    }