Created
July 7, 2014 07:51
-
-
Save omas/bf5f7cd446aae7515498 to your computer and use it in GitHub Desktop.
入力が仕様通りではない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <!-- | |
| 入力から、n個の年齢を受け取り、その平均年齢を算出するプログラムを作成してください。年齢は引数から取得するものとします。 | |
| 1. 年齢は、引数から取得する。 | |
| 2.引数が指定されていない場合は「引数に年齢を指定してください」のメッセージを表示する。 | |
| --> | |
| <script> | |
| (function main(){ | |
| if (arguments.length == 0) { //condition 2 | |
| output("引数に年齢を指定してください"); | |
| return ; | |
| } | |
| output(average(arguments)); | |
| })(23,45,77); //condition 1 | |
| function average(data){ | |
| var sum = 0; | |
| for (var index in data){ | |
| sum += data[index]; | |
| } | |
| return sum / data.length; | |
| } | |
| function output(text){ | |
| alert(text); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment