If you comment out the first, then only the second is executed. If the second and first, then only the third document.write is executed.

<html> <head> <title>Object Oriented Javascript</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <script type="text/javascript"> function SecretCode(){ var secretNum = 78; this.guessNum = function(num){ if(num > 78){ return "Lower"; }else if(num < 78){ return "Higher"; }else{ return "You guessed it"; } } } var secret = new SecretCode(); document.write("Value of secretNum " + secret.secretNum + "<br /"); document.write("Is 70 the number " + secret.guessNum(70) + "<br /"); SecretCode.prototype.getSecret = function(){ return this.secretNum; } document.write("The secret number is " + secret.getSecret() + "<br /"); </script> </body> </html> 

  • close tag: ... + "<br />" - Igor

1 answer 1

All that is written after the first unclosed <br /

 document.write("Value of secretNum " + secret.secretNum + "<br /"); 

It appears inside this tag - its attributes, and outside it is not visible.

  <html> <head> <title>Object Oriented Javascript</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <script type="text/javascript"> function SecretCode(){ this.secretNum = 78; this.guessNum = function(num){ if(num > 78){ return "Lower"; }else if(num < 78){ return "Higher"; }else{ return "You guessed it"; } } } var secret = new SecretCode(); document.write("Value of secretNum " + secret.secretNum + "<br />"); document.write("Is 70 the number " + secret.guessNum(70) + "<br />"); SecretCode.prototype.getSecret = function(){ return this.secretNum; } document.write("The secret number is " + secret.getSecret() + "<br />"); </script> </body> </html> 

  • After two years of learning Java, I came to the necessity of learning javascript. I was not mistaken?))) - Nikolay Belyakov
  • @Nikolai Belyakov Of course not. You have a lot of fun minutes ahead). - Igor