南邮Web技术第四章作业_第1页
南邮Web技术第四章作业_第2页
南邮Web技术第四章作业_第3页
南邮Web技术第四章作业_第4页
南邮Web技术第四章作业_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论