Friday, 19 August 2016

JAVA SCRIPT OUTPUT

    Apart from the unquestionable ability of java-script to take input it has an even cooler way of outputting to ensure user friendliness no one would want to keep inputting and inputting without seeing an output or will you love that?
   Today we are going to be discussing the 4 major way of outputting using java-script .
  • Writing into an alert box, using window.alert(). or just alert()  an alert box is popup screen that displays an output it seizes all action on your browser until you have attended to the output screen this is implemented using the following syntax
      Window.alert("text goes here") or window.alert(calculation goes here).
      you can also decide to just use alert
        alert("text goes here") or alert(calculation goes here).

example
   <!DOCTYPE html>
<html>
<body>

<h1>My First java script example</h1>

<script>
alert("i love you");
</script>

</body>
</html>

  • Writing into the HTML output using document.write(). this is also a cool way of outputting in java script instead of bringing out a popup box you can just write on your browser page direct this is implemented using the following syntax
          document.write("text goes here"), or document.write(calculation goes here)
          • Writing into an HTML element, using innerHTML.
        this is use instead of opening your script tag you can have an element implement the function for you example:
        <html>
        <body>

        <h1>My First Web Page</h1>
        <p>My first paragraph.</p>

        <button onclick="document.write(98+ 6)">Try it</button>

        </body>
        </html>
          • Writing into the browser console, using console.log(). to view this you need to Activate debugging in your browser (Chrome, IE, Firefox) with F12, and select "Console" in the debugger menu.
        example

      • <h1>My First Web Page</h1>

        <script>
        console.log(5 + 6);
        </script>

        </body>
        </html>

      • thats all for now hope this page was helping take time in sharing with your friend and making your comment

    •     
Share:

0 comments:

Post a Comment