(完整word版)南邮Web技术第四章作业.doc
上传人:羽沫****魔王 上传时间:2024-09-11 格式:DOC 页数:5 大小:196KB 金币:10 举报 版权申诉
预览加载中,请您耐心等待几秒...

(完整word版)南邮Web技术第四章作业.doc

(完整word版)南邮Web技术第四章作业.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

10 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Web技术第四章作业———————————作业4.2—————————————Write,test,anddebug(ifnecessary)JavaScriptscriptsfortheproblemsthatfollow.Whenrequiredtowriteafunction,youmustincludeascripttotestthefunctionwithatleasttwodifferentdatasets.Inallcases,fortesting,youmustwriteanXHTMLfilethatreferencestheJavaScriptfile.4.2Output:Thefirst20Fibonaccinumbers,whicharedefinedasinthesequence1,1,2,3,…whereeachnumberinthesequenceafterthesecondisthesumofthetwopreviousnumbers.Youmustusedocument.writetoproducetheoutput.<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Fibonaccinumbers</title><script>functionf(x){returnx<2?1:(f(x-1)+f(x-2));}functionout_f(){document.write("Thefirst20Fibonaccinumbers:");for(vari=0;i<20;i++){document.write(f(i)+",");}}</script></head><body><inputtype="button"value="Fibonaccinumbers"onclick="out_f()"/></body></html>结果截图:———————————作业4.11—————————————4.11Function:counterParameter:Anarrayofnumbers.Returns:Thenumbersofnegativeelements,zeros,andvaluesgreaterthanzerointhegivenarray.Note:Youmustuseaswitchstatementinthefunction.<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>counter</title><script>functioncounter(list){vari,s=[0,0,0];//定义记录负数、零、正数个数的数组s,并初始化各数据为0for(i=0;i<list.length;i++){switch(true){//进行条件判断负数、零、正数,并对数组s中各元素计算个数case(list[i]<0):s[0]++;break;case(list[i]===0):s[1]++;break;case(list[i]>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,2,8,5,-15,0];//数组1varmy_list_2=[-2,-1,0,0,1,2];//数组2vars1=counter(my_list_1);//利用函数counter计算数组1各数据个数,并存储在s1中vars2=counter(my_list_2);//利用函数counter计算数组2各数据个数,并存储在s1中document.write("thefirstarray:",my_list_1,"<br/>");//输出数组1document.write("thesecondarray:",my_list_2,"<br/>");//输出数组2document.write("Thenumbersofnegativeelements,zeros,andvaluesgreaterthanzerointhefirstarray:",s1