Formatting your code with the right indentation can help you a lot...
See the first else - it belongs the the inner if, but there is no closing } after it so the second else is pair-less...
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 slew the Dragon");
slaying = false
} else {
youHit = Math.floor(Math.random() * 2)
}
else {
console.log("The dragon defeated you");
slaying = false;
}
}