[JavaScript] 08 Function

less than 1 minute read

Published:

In this post, 08 JavaScript lecture is introuduced.

Function

<script>
	function sum(left, right){
    return left+right;
  }
  document.write(sum(2,3)+'<br>');
  document.write('<div style="color:red">'+sum(2,3)+'</div>');
</script>
<!doctype html>
<html>
<head>
    <title>WEB1 - html</title>
    <meta charset="utf-8">
    <script>
    function nightDayHandler(self){
        var target = document.querySelector('body');
        if(self.value === 'night'){
            target.style.backgroundColor = 'black';
            target.style.color = 'white';
            self.value = 'day';

            var alist = document.querySelectorAll('a');
            var i = 0;
            while (i < alist.length){
                alist[i].style.color = 'powderblue';
                i = i + 1; 
            }
        } else{
            target.style.backgroundColor = 'white';
            target.style.color = 'black';
            self.value = 'night';

            var alist = document.querySelectorAll('a');
            var i = 0;
            while (i < alist.length){
                alist[i].style.color = 'blue';
                i = i + 1; 
            }
        }
    }
    </script>  
</head>

<body>
    <h1><a href="index.html">WEB</a></h1>
    <input type="button" value="night" onclick="
        nightDayHandler(this);
    ">
    <ol>
        <li><a href="1.html">HTML</a></li>
        <li><a href="2.html">CSS</a></li>
        <li><a href="3.html">JavaScript</a></li>
    </ol>
    <h2> JavaScript</h2>
    I'm <u>studying</u> <strong>html</strong>.<br>
    Visit <a href="https://developer.mozilla.org/ko/docs/Web/JavaScript">HERE</a> if you want to see the official document of JS.
    <img src="coding.jpg" width="100%">
</body>
</html>

Leave a Comment