Dragon slayer not working


#1



I am trying to solve the very easy issue of Dragon Slayer on this link:
https://www.codecademy.com/en/courses/javascript-beginner-en-mrTNH-6VIZ9/0/2

But somehow codeAcademy wont mark it as done returning an issue of: "Looks like you didnt se the 'slaying' to true". I thought i was wrong somewhere so i really compared the code with some people suggestion and my code was the same as theirs.
I dont know whats wrong kindly help me with it. Here is my code:

var slay = true;
var youHit = Math.floor(Math.random() * 2);
var damageThisRound = Math.floor(Math.random() * 5 + 1);
var totalDamage = 0;
while (slay) {
  if (youHit===1) {
    console.log("You did this much damage: " + damageThisRound);
    totalDamage += damageThisRound;
    if (totalDamage >= 4) {
      console.log("You slayed the dragon!");
      slay = false;
    } else {
      youHit = Math.floor(Math.random() * 2);
    }
  } else {
    console.log("Sorry, You're toasted.");
    slay = false;
  }
}


#2

Maybe it is just picky about the name and you need to use slaying instead of slay.
Otherwise it seems to be fine.


#3

I tried that as well. I thought maybe the issue could be that codeAcademy is setting some check to imagine if a learner is copy pasting the old code. Hence, its a fail.


#4

Ok I did what I should have done earlier :slight_smile: (clicking the link).
And as far as I can see the problem is that you're ahead of the game. Meaning you already have a final version of the game whereas at this point the exercise just expects you to have:

Spoiler Alert for anyone else!

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

The obvious difference is that in your case slaying is already false because the game is over whereas with the expected code slaying would be true because the game has not even started yet.


#5

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