版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、WelK术第四章作业Write, test, that follow. to test the for testing, file.scripts for the problems you must include a scriptdata sets. In all cases, references the JavaScript作业4.2and debug (if necessary) JavaScript When required to write a function, function with at least two different you must write an XHT
2、MLfile that4.2 Output : The first 20 Fibonacci numbers, which are defined as in the sequence 1,1,2, 3,whereeach number in the sequence after the second is the sum of the two previous numbers. You mustuse document.write to produce the output. <! DOCTYPEhtml> <html ><head ><meta c
3、harset ="UTF-8" ><title >Fibonacci numbers</ title ><script >function f (x) return x<2?1: (f(x -1)+f(x -2); function out_f ()document .write( "The first 20 Fibonacci numbers :");for (var i =0;i <20;i +) document .write(f(i) + ","); </ scrip
4、t ></head ><body ><input type ="button" value ="Fibonacci numbers" onclick =" out_f () " /> </body ></ html >结果截图:卜 botiacci作业4.114.11 Function : counterParameter : An array of numbers.Returns : The numbers of negative elements, zeros, a
5、nd values greaterthan zero in the given array.Note : You must use a switch statement in the function.<! DOCTYPEhtml><html ><head ><meta charset ="UTF-8" ><title >counter</ title >script >function counter (list ) var i,s = 0,0,0;/定义记录负数、零、正数个数的数组s,并初始化
6、各数据为0for (i =0; i < list.length; i +) switch (true ) /进行条件判断负数、零、正数,并对数组s中各元素计算个数case (listi < 0):s 0 +;break ;case (listi = 0):s 1 +;break ;case (listi > 0):s 2 +;break ; returns; </ script ></head ><body >script >varmy_list_1 = 1, 5,5, 1, 5, 2,-2, -8,2, 0, 3,65,5, -6,
7、 2, 8,5, -15, 0;/ 数组 1var my_list_2 = - 2, -1, 0,0, 1, 2;var s1 = counter (my_list_1);数据个数,并存储在s1中一一var s2 = counter (my_list_2);数据个数,并存储在s1中一一document .write( "the first array :"输出数组1/数组2/利用函数counter计算数组1各/利用函数counter计算数组2各,my_list_1, "<br/>");document .write( "the se
8、cond array : " ,my_list_2, "<br/>" );输出数组2document .write( "The numbers of negative elements, zeros, and values greater than zero in the first array : ",s1, "<br/>" );/ 输出数组1的计算结果document .write( "The numbers of negative elements, zeros, and values
9、 greater than zero in the second array : ",s2, "<br/>" );/输出数组2的计算结果</ script ></ body >结果截图:</ html >tho first array: 155J5Z2 8Z0365Sthe second array : -Z-LQQJ2-he numbers of negative elements, zeros, and values greater than zero in the first array : 421?The n
10、umbers of negative 国。m自nts, 2&ros, and values grsater than 2rc in the second array : 2,2,2作业 4.134.13 Function : row_averagesParameter : An array of arrays of numbers.Returns : An array of the averages of each of the rows of the given matrix.<! DOCTYPEhtml><html ><head ><met
11、a charset ="UTF-8" ><title >row_averages</ title><script >function row_averages ( m)var i,j,m; / 定义矩阵 mvar x = m.length; / 求矩阵行数x ,列数yvar y=;var sum=,n =;/ 定义每行元素数值之和 sum, 每行元素数值的平均值 nfor (i =0;i <x;i +)/ 循环求解每行元素平均值nyi = mi.length;/求矩阵每行包含元素的个数sumi = 0;for (j =0;j
12、<yi;j+)/求每行元素数值之和sumsumi = mij+ sumi;ni = (sumi / yi);/ 求每行元素数值的平均值nreturn n; / 返回每行元素数值的平均值n</ script ></ head ><body ><script >var m1 = 11 , 51 , 43,/ 定义两个数组 40, 15, 65, 72, 88, 98;var m2 = 1, 2, 3, 4, 5, 6, 7,8,9;var n1 = row_averages(m1);数组的行平均值数组n1,n2var n2 = row_aver
13、ages(m2);document .write( "The first matrix :第一个矩阵及其平均值for (var k=0;k <m1.length;k +) document .write(m1k, "/调用row_averages 函数求两个,"<br />");/ 输出average : " ,n1k, "<br />");document .write( "<br />", "The second matrix : ", "<br />");输出第二个矩阵及其平均值for (var k=0;k <m2.length;k +) document .write(m2k, " average : " ,n2k, "<br />");</ script ></body ></
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年河北省霸州市高考物理学业考试试卷及参考答案详解【夺分金卷】
- 2026年江苏省邳州市高考物理5月学情自测试卷附答案详解【B卷】
- 2026年河南省邓州市高考物理自主招生测试卷附答案详解(完整版)
- 2026年江西省樟树市高考物理一轮复习试卷(典优)附答案详解
- 2025年山东省海阳市高考物理自主招生模拟卷及完整答案详解(必刷)
- 2025年四川省华蓥市高考物理强基计划测试卷附答案详解(模拟题)
- 2025年四川省简阳市高考物理真题汇编考试卷含答案详解【轻巧夺冠】
- 2025年江苏省仪征市高考物理自主招生试卷含答案详解【黄金题型】
- 2025年吉林省德惠市高考物理学业考试模拟卷附参考答案详解【培优B卷】
- 2026年四川省邛崃市高考物理周测试卷含答案详解(能力提升)
- 常考2026年交管12123学法减分复习考试题库及参考答案完整版
- 2026贵州交投产业集团有限公司第一批次公开招聘考试参考试题及答案详解
- 2025-2026学年上海市青浦区沪教版三年级下学期期末数学检测试题 含答案
- 2026广东广州市海珠区人力资源和社会保障局招聘中级雇员2人考试模拟试题及答案详解
- 2026年南充市中考物理试卷(含答案)
- 2025年贵阳市中考地理试卷(含答案解析)
- 四川省南充市普通高中2024-2025学年高一下学期期末学业质量监测地理试题(原卷版)
- 高中地理教师考试教案模板
- Q-JJJ 9002-2025 铁路建设项目安全穿透式管理实施指南
- 2025-2030年中国液体燃烧油行业竞争格局及投资发展预测研究报告
- 农业职业经理人考试的实操能力评测试题及答案
评论
0/150
提交评论