数组中的元素为奇数的平均值求出来
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>网页标题</title> <meta name="keywords" content="关键字列表" /> <meta name="description" content="网页描述" /> <link rel="stylesheet" type="text/css" href="" /> <style type="text/css"></style> </head> <body> <script type="text/javascript"> //定义一个数组这个数组中有9个元素然后将这个数组中的元素为奇数的平均值求出来 var sum=0; var arr=[97,12,23,58,41,74,19,22,15]; for (var i=0;i<arr.length;i++){ if (arr[i]%2!=0){ sum +=arr[i]; } } document.write(sum); </script> </body> </html>