<!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>
More than 3 years have passed since last update.
【JavaScript】配列の値から平均値を計算する関数calc_aveを定義し、配列dataの平均値を表示するプログラムを作成せよ。
Last updated at Posted at 2021-05-08
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme