Damage is not a function message


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-mrTNH-6VIZ9/0/6?curriculum_id=506324b3a7dffd00020bf661


My game works perfectly and it passes me to the next excercise but I keep getting the following message:

_TypeError: totalDamage is not a function**_**

I'm just wondering whats going on with it, and why that message would keep being displayed.

Thanks.


var slaying = true;
var youHit =Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random() *5 + 1);
var totalDamage = 0;

while(slaying) 
{
    if(youHit) 
    { console.log('You hit the dragon!');
        totalDamage+=damageThisRound 
        {
            if (totalDamage>=4) {
                console.log('You slayed the dragon');
                 slaying=false;
            } else { 
                youHit=Math.floor(Math.random() * 2);
            }
        }
    } else {
        console.log('The dragon defeated you.');
        }
    slaying=false;
}

totalDamage() = (totalDamage += damageThisRound);


#2

When you add the () to totalDamage, that's syntax for a function call. If you just write totalDamage, it shouldn't give you an error.


#3

Oh, Awesome! Not sure why I put () in the first place. Thank you!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.