First, the Process Control statement (if statement) in JS
Format:
if ( condition 1) {
if condition 1 is established, execute the code here
}Else{
if the condition is not true , execute the code here
}
format :
if ( condition 1) {
if condition 1 is established, execute the code here
}else if( condition 2) {
if Condition 2 is established, execute the code here
}else if( condition 3) {
If Condition 3 is established, execute the code here
}..........
Else {
if condition 1 to condition n is not true, execute the code here
}
Nested formats:
if ( condition 1) {
if ( condition ) {
if the condition is true , execute the code here
}
}Else{
if condition 1 is not true, execute the code here
}
/*If statement if (condition 1 is true) {if condition 1 is set up, execute the code here}else{if the condition is not true, execute the code here}*/varNUM1 = 10;varnum2 = 20;if(NUM1<NUM2) {//Ten <Alert ("NUM1");}Else{alert ("Num2");} Multiple selection notationvarstr = "3";if(str== "1") {alert ("1");}Else if(str== "2") {alert ("2");}Else if(str== "3") {alert ("3");// here, here.}Else{alert ("6");}//If statement nestingvarnum = 10;varstr = "20";if(num = = 10 ){ if(str== "20") {alert ("True I popped in here"); }}Else{alert ("False, I'm here.");}
View Code
JS in the system input box
prompt () //System input Box
IsNaN ()://Check whether it is a digital
if IsNaN (Ten) writes that the number returns false
if IsNaN ("haha") does not write a number to return the result to True
//1 "If you enter a 100 hint: out of//2 "greater than or equal to 60 hint: pass//3 "Less than or equal to 59 hint: failedvarstr = prompt ("Judging if your grades meet the requirements");if(IsNaN (str)) {alert ("Number must be entered");}Else if(str==100) {alert (Out);}Else if(str>=60| | Str<=99>) {alert (Failed);}Else if(str<=59) {alert ("Failed");}
View Code
JS in the Process Control statement (switch statement)
Format:
Switch ( conditional expression ) {
Case Constants 1:
implementation ;
Break
Case Constants 2:
implementation ;
Break
Case Constants 3:
implementation ;
Break
......
Default
Perform
}
/*if (condition 1) {1 satisfies execution}else if (condition 2) {2 satisfies execution}else{If none is satisfied, execute;}*/varstr = "2";Switch(str) { Case"1": Alert ("1"); Break; Case"2": Alert ("2");//I'm doing it here . Break; Case"3": Alert ("3"); Break; default: Alert ("Neither satisfies execution: default");}
View Code
Second, the Loop statement in JS (for Loop)
Looping statements: In a limited number of conditions, repeated execution of some things
for Loop Format:
for ( starting condition ; Termination Conditions ; Step Value ){
circulation body ;
}
for (var i=1;i<=100;i++) { document.write (i+ "<br/>");}
Nested for loop statements in JS
Format:
for ( starting condition ; Termination Conditions ; Step Value ){
for ( starting condition ; Termination Conditions ; Step Value ){
circulation body ;
}
circulation body ;
}
Nested Statements for(vari=0;i<=3;i++) {//0 1 2 3 for(varj=1;j<5;j++) {//1 2 3 4document.write (J+ "<br/>"); } //document.write (i+ "<br/>");}//2 "3 6 9 12 15 18 .... The remainder of the 3 i%2==0/*For (Var i=1;i<=100;i++) {if (i%3==0) {document.write (i+ "<br/>"); }//document.write (i+ "<br/>");}*///1 "from 1 to 100 numbers//2 "2 4 6 8 10 ... The remainder of the 2 i%2==0 for(vari=1;i<=100;i++){ if(i%10==0) {document.write (i+ "<br/>"); }} multiplication Table small demo//I=1 j=1 j<i+1 that is j<2 cycle once 1*1//i=2 j=1 j<i+1 that is j<3 cycle two times 1*2 2*2//i=3 j=1 j<i+1 namely J<4 cycle three times 1*3 2*3 3*3//i=9 j=1 j<i+1 is j<10 that cycle nine times 1*9 ..... 9*9 for(vari=1;i<=9;i++){ for(varj=1;j<i+1;j++) {document.write (J+ "*" +i + "=" +j*i+ " " ); } document.write ("<br/>");}
View Code
............ Add
JavaScript Process Control Statements-loops