- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>我的FOR迴圈</title>
- </head>
- <body>
-
- <script type="text/javascript">
- var start = parseInt(prompt("請輸入起始數字"));
- var end = parseInt(prompt("請輸入結束數字"));
- var total = 0
- for(var a = start; a <= end; a++)
- {
- total = a + total;
- document.write(a + " | " + total );
- document.write("<br />");
- }
- alert("總和是:" + total)
- </script>
- </body>
- </html>
複製代碼 |