0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

複数の数値が定義されている配列data1とdata2から「data1とdata2を合わせた平均値」と「平均値以上の数値」を表示せよ

Posted at
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>課題</title>
    <script>
        var data1 = [59, 39, 100, 2, 15, 40, 84, 97];
        var data2 = [63, 18, 64, 97, 50, 98];
        document.write('<p>【data1】' +data1  + '</p>'); 
        document.write('<p>【data2】' +data2  + '</p>'); 

        var data3 = [];
        var sum = 0;
        var ave = 0;

        for(var i = 0; i < data1.length; i++){
          data3.push(data1[i]);
        } 
        for(var i = 0; i < data2.length; i++){
          data3.push(data2[i]);
        } 

        document.write('<p>【マージ後】' +data3  + '</p>'); 

 
        for(var i = 0; i < data3.length; i++){
          sum = sum + data3[i]
        } 

        ave = sum / data3.length;
        
        document.write('<p>data1とdata2を合わせた平均値' +ave+ '</p>'); 

        document.write('<p>平均値以上の数値は以下</p>'); 



        for(var i = 0; i < data1.length; i++){
          if( data1[i] >= ave)
          document.write('<p>data1:' +data1[i]+'</p>'); 
        } 

        for(var i = 0; i < data2.length; i++){
          if( data2[i] >= ave)
          document.write('<p>data2:' +data2[i]+'</p>'); 
        } 

    </script>
</head>
<body>
</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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?