Task : We make a weekly plan, 周一、二 learning concept knowledge, Wednesday to enterprise practice, Friday experience, week Six, rest and entertainment. Make a choice based on the day of the week and use the switch statement to complete.
Code:
<! DOCTYPE html><html><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " /><title>Switch</title><script type="Text/javascript">varMyweek =4;//myweek represents the day of the week variableSwitch(Myweek) { Case 1: Case 2: document.write ("Learning concept knowledge"); Break; Case 3: Case 4: document.write ("to Enterprise Practice"); Break; Case 5: document.write ("Experience"); Break; Case 6: Case 7: document.write ("Week Six Rest and entertainment"); Break;default: document.write ("Oh!my god!what day!!");}</script></head><body></body></html>
Demo Effect:
task Source: MU class Web--"JavaScript advanced"--Multiple options (switch statement)--programming exercises
In a college programming elective class, we got a group of student data for the class, name, gender, age, and grade, and then we're going to use JavaScript to pick out the names of all the girls who are freshmen.
student information is as follows:
Task decomposition
The first step: to make an array of these data, so that we operate after the OH.
提示: 使用二维数组。
The second step: Filter the Data bar, first to find all the information is a freshman;
The third step: Finally again filter the previous step to get data, print out all the names of girls;
提示: 可以用switchif 语句进行筛选。
Code (version one):
<! DOCTYPE html><html ><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " /><title></title><script type="Text/javascript">varInfos = [[' Little A ',' Woman ', +,' Freshman '], [' Little B ',' man ', at,' Juniors '], [' Little C ',' man ', -,' Seniors '], [' Little C ',' man ', -,' Seniors '], [' Little d ',' Woman ', +,' Freshman '], [' Little e ',' Woman ', A,' Seniors '], [' Little F ',' man ', +,' Freshman '], [' Little g ',' Woman ', A,' sophomore '], [' Little h ',' Woman ', -,' Juniors '], [' small I ',' Woman ', -,' Freshman '], [' Little J ',' man ', -,' Juniors ']]; for(vari =0; i < infos.length; i++) {if(infos[i][3] ==="Freshman"&& infos[i][1] ==="female") {document.write (infos[i][0] +"<br/>"); }}</script></head><body></body></html>
Code (version two):
<! DOCTYPE html><html ><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " /><title>Process Control Statements</title><script type="Text/javascript"> The first step is to write the previous data in the form of an array, defining the variable as Infos varinfo = [[' Little A ',' Woman ', +,' Freshman '], [' Little B ',' man ', at,' Juniors '], [' Little C ',' man ', -,' Seniors '], [' Little d ',' Woman ', +,' Freshman '], [' Little e ',' Woman ', A,' Seniors '], [' Little F ',' man ', +,' Freshman '], [' Little g ',' Woman ', A,' sophomore '], [' Little h ',' Woman ', -,' Juniors '], [' small I ',' Woman ', -,' Freshman '], [' Little J ',' man ', -,' Juniors ']];//First screening, find out all the information of a freshman varnum =0, key =0;varInfos =New Array(); for(varI=0;i<5; i++) {Infos[i] =New Array(); for(varj=0;j<2; j + +) {Infos[i][j] = Info[num]; num++;if(infos[i][j][3] =="Freshman") {document.write (infos[i][j]); document.write ("<br/>"); Info[key] = Infos[i][j]; key++; } } }//second screening to find out all girls ' informationdocument.write ("<br/> secondary screening: <br/>") for(varQ =0Q < key;q++) {if(info[q][1] =="female") {document.write (info[q]); document.write ("<br/>"); } }</script></head><body></body></html>
Demo Effect:
task Source: MU class Network--"JavaScript advanced"--process Control statement--programming challenge
Front-end practice--javascript--flow control statements