LoginSignup
0
0

More than 1 year has passed since last update.

【JavaScript】配列の値から平均値を計算する関数calc_aveを定義し、配列dataの平均値を表示するプログラムを作成せよ。

Last updated at Posted at 2021-05-08
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>課題</title>
</head>
<body>
  <script>
    var data = [59, 39, 100, 2, 15, 40, 84, 97];
    var ave; // 平均値 
    // 関数calc_aveを実行する
    function calc_ave() {
      var sum = 0; // 平均値
      for(var i = 0; i < data.length; i++){
      sum = sum + data[i]
      document.write('<p>' + sum + '</p>');
      } 
      ave = sum / data.length;
      document.write('<p>平均値:' +ave+ '</p>'); 
    }
    calc_ave();
</script>
</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0