Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, November 27, 2012

Codecademy: "The second 'if statement"


//sample solution

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
console.log("youHit is " + youHit);
var damageThisRound = Math.floor(Math.random() * 5 + 1);
console.log("The amount of damage dealt this round is " + damageThisRound);
var totalDamage = 0;

console.log("The total damage received is " + totalDamage);
while(slaying){
if(youHit){
totalDamage = totalDamage + damageThisRound;
console.log("The total damage received is " + totalDamage);
if(totalDamage >= 4){
console.log("Congratulations! You've slayed the dragon.");
slaying = false;
}
else{
youHit = Math.floor(Math.random() * 1);
}
}
else{
console.log("The dragon defeated you!");
slaying = false;
}
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts