Code prints FALSE. Why?


#1


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

Hello,

The code I pasted here works but I would like to now why does it print false whenever I run it. I only used console.log for the sentences. Is there a method to stop this?


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){
     
      totalDamage= totalDamage + damageThisRound;
      if (totalDamage >= 4) {
           console.log("Congratulations you killed the dragon");
      slaying=false;
          
      }
      else {
       youHit = Math.floor(Math.random()*2);  
      }
      
  }
  else {
   console.log("The dragon defeated you!");
   slaying=false;
  }
 }


#2

it is just the codecademy console doing this, some consoles do it

Don't worry about it, js is mostly used in webpages and then console is only used for debugging, for displaying on a webpage you use a different technique


#3

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