if...else





js/script.js
  • var val = true;
  •  
  • function funMake() {
  •  if(val) {
  •   document.write('Hello World!' + '<br />');
  •  }
  •  else {
  •   document.write('To be or not to be?' + '<br />');
  •  }
  • }
var val = true;

function funMake() {
 if(val) {
  document.write('Hello World!' + '
'); } else { document.write('To be or not to be?' + '
'); } }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  funMake();
  • </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  funMake();
  • </script>
  • </body>
  • </html>