/5 Syntax Error, Pleae help :) (Solved)


#1

So here was my code :

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 === 1){
            console.log("You hit the dragon!")
            if (totalDamage >= 4) {
                console.log("You slayed the dragon's stinky ass")
                slaying = false;}
                else {
                    youhit = Math.floor(Math.random() *2);}}
        totalDamage += damageThisRound;
        else {
            console.log("The Dragon slayed your ass");
        slaying = false; };

Here is the outcome :slightly_smiling: :smile:

SyntaxError: expected expression, got keyword 'else'

Where is my error ? :stuck_out_tongue:


#2

Try moving the statement on line 13 to line 8 (under "You hit the dragon!").

Btw for readability, you might want to get used to correct formatting. This will make it easier and faster for others to check your code, and for you if you come back to it in the future.