07_ for 练习 _ sumOfOdd

  • <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>Sum of Odd/Even</title>
        </head>
        <body>
            <script type="text/javascript">
                var sumOdd = 0;
                var sumEven = 0;
                var i;
                
                for(i=1; i<=100; i++)
                {
                    if(i%2 != 0)
                    {
                        sumOdd += i;
                    }
                    else
                    {
                        sumEven += i;
                    }
                }
                document.write("The sum of 1~100 odd is "+sumOdd+"<br />");
                document.write("The sum of 1~100 even is "+sumEven+"<br />");
            </script>
        </body>
    </html>

     

posted @ 2018-09-19 22:46  耶梦加德  阅读(155)  评论(0编辑  收藏  举报