js process control, if judgment, switch loop and other requirements. Practice more and lay a solid foundation.

Process control

I. Introduction to process control

1.1 what is process control

The control process (also known as process control) is computer A term used in the field of computing, meaning program At runtime, individual instructions (or statements subroutine )Run or evaluation The order of. Whether in Declarative programming language or Functional programming language There are similar concepts in.

Our current code is executed from top to bottom and once. Sometimes, we need to make a piece of code execute selectively, execute multiple times, and so on.

Therefore, we need to use process control statements, which can help us complete the selective execution of code, circular execution and so on.

1.2 judgment statement / conditional statement

Conditional statements are used to judge whether a given condition is satisfied (whether the expression value is 0) and determine the executed statement according to the judgment result (true or false). The selection structure is realized by conditional statements.

1.3 if judgment

Syntax structure:

if (conditional expression) {code block}

Execution process:

First, execute the conditional expression. When the conditional expression is true, execute the code block in braces. When the condition is not true, the code block in braces is not executed.

<script type="text/javascript">
						
			var  a = prompt("Please enter a number");
			
			//The box will pop up when the number entered by the user is > 90
			
			if( a>90  ){
				alert(123);
			}
		
</script>

Exercise: Please input Linghu Chong's java test score. If it is less than 60, output to think about it.

1.4 if else judgment

Syntax structure:

if (conditional expression) {code block} else {code block}

Execution process

First, execute the conditional expression. If the condition is true, execute the code in if braces. If the condition is not true, execute the code in else braces.

That is, there is only one code block of if and else that can be executed

Exercise: Please input Linghu Chong's java test score. If it is less than 60, output to think about the cliff. Otherwise, you will be rewarded with Zixia divine skill.

<script type="text/javascript">
			
			var  s = prompt("Please enter Linghu Chong");
			
			if(s<60) {
				document.write("Don't think about the past");
			}else{
				document.write("Excellent Zixia skill");
			}
				
		</script>
1.5 multi condition judgment

Exercise: Please input Linghu Chong's java score and music score. If the java score is greater than 80 and the music score is greater than 60, the reward will be output, otherwise Siguo cliff.

Scenario A: nested judgment

<script type="text/javascript">
			var s1 = prompt("Please enter Linghu Chong Java achievement");
			var s2 = prompt("Please enter Linghu Chong's music score");

			if (s1 > 80) {
				if (s2 > 60) {
					document.write("Reward you Zixia magic skill");
				} else {
					document.write("Let's go over the cliff");
				}
			} else {
				document.write("Let's go over the cliff");
			}
		</script>

Method B: & & and connect multiple conditions, which means that the whole is true only when multiple conditions are true

<script type="text/javascript">
			
			var s1 = prompt("Please enter Linghu Chong Java achievement");
			var s2 = prompt("Please enter Linghu Chong's music score");

			if( s1 >80 && s2>60 ){
				document.write("Reward you");
			}else{
				document.write("Siguo cliff");
			}
			
		</script>

Exercise: Please input Linghu Chong's java score and music score. If the java score is greater than 80 or the music score is greater than 60, the reward will be output, otherwise, Siguo cliff.

Scenario A: nesting

Scheme B: | or connect multiple judgment conditions. As long as one is true, the whole is true

<script type="text/javascript">
			
			var s1 = prompt("Please enter Linghu Chong Java achievement");
			var s2 = prompt("Please enter Linghu Chong's music score");

			if( s1 >80 || s2>60){
				document.write("Reward you");
			}else{
				document.write("Siguo cliff");
			}
			
		</script>
1.6 interval judgment if else

Exercise: Please input Linghu Chong's java score. If it is greater than 90, the output is excellent, the output between 80-90 is good, the output between 70-80 is average, and the output below 70 is very poor

	<script type="text/javascript">
			
			var s1 = prompt("Please enter Linghu Chong Java achievement");
			
			
			if(s1>90){
				document.write("excellent");
			}else if( s1 > 80  ){
				document.write("good");
			}else if( s1 > 70 ){
				document.write("commonly");
			}else {
				document.write("Very bad");
			}
		
		</script>

Syntax structure:

If (conditional expression 1) {code block} else if (conditional expression) {code block} else {code block}

① else-if can add more than one ② else-if must be executed when the previous conditions are not met

③ The interval shall be allocated reasonably during interval judgment

Exercise question: Please input a person's height and weight, and the output is fat and thin according to the formula

Formula: standard weight = height - 105; Floating up and down 3;

	<script type="text/javascript">
			
			/**
			 *  Please input a person's height and weight. The output is fat and thin according to the formula. It is normal
                Formula: standard weight = height - 105; Floating up and down 3;	
				
			 */
			var  h = prompt("Please enter your height");
			var  w = prompt("Please enter your weight");
			
			var  b =  h - 105;
			var  min = b-3;
			var  max = b+3;
			
			if ( w < min ){
				document.write("Thin ");
			}else if( w >  max){
				document.write("Overweight");
			}else{
				document.write("normal");
			}
			
		</script>
1.7 swtich-case
	<script type="text/javascript">
			
			var  num = prompt("Please enter the response case and select the function you need");
			/***
			switch((variable){
				case Value: code block break; 
				case Value: code block break; 
				case Value: code block break; 
				case Value: code block break; 
				case Value: code block break; 
				default :          ;
			}
			
			*/
			switch(num){
				case  "1" :
				    document.write("artificial intelligence");
				   break;
				case  "2" :
				    document.write("Artificial intelligence");
				   break;
				case  "3" :
				    document.write("Functional Homo sapiens");
				   break;
				
				default:
				    document.write("This function is not available");
			}
			
		</script>
1.8 personal income tax calculator

Individual income tax = (salary - three insurances and one fund - individual income tax threshold) x tax rate - quick calculation deduction

The "salary - three insurances and one fund - individual income tax threshold" in parentheses is usually referred to as "taxable income" or "taxable amount"

****Salary * * * *: i.e. initial income (income written in the contract)

****Threshold * * * *: since 2011, the threshold has been raised from 2000 yuan to 3500 yuan

The threshold of 3500 is not that you have to pay personal income tax if your salary exceeds 3500

It's the salary - after the three insurances and one fund, it's more than 3500 before paying personal income tax

****Tax rate * * * *: increased from 3% to 45%, with 7 grades corresponding to taxable income in 7 different ranges

****Quick calculation deduction * * * *: from 0 to 13505, there are also 7 levels, corresponding to different tax rates:

Monthly taxable incometax rateQuick deduction (yuan)
The monthly tax payable shall not exceed 1500 yuan3%0
The monthly tax payable exceeds 1500 yuan to 4500 yuan10%105
The monthly tax payable exceeds 4500 yuan to 9000 yuan20%555
The monthly tax payable exceeds 9000 yuan to 35000 yuan25%1005
The monthly tax payable exceeds 35000 yuan to 55000 yuan30%2755
The monthly tax payable exceeds 55000 yuan to 80000 yuan35%5505
The monthly tax payable exceeds 80000 yuan45%13505

Note: ① the tax grade distance and tax grade distance not included in the table are the income after deducting relevant expenses in accordance with the provisions of the tax law.

② The tax inclusive step applies to the income from wages and salaries paid by taxpayers; the tax exclusive step applies to the income from wages and salaries paid by others (units).

For example, if the monthly salary is 6000 yuan and the workplace is Guangzhou (pension insurance 8%, medical insurance 2%, unemployment insurance 1%, housing provident fund 8%), then "tax payable" = 6000 - 6000x (8% + 2% + 1% + 8%) -3500 = 1360 yuan. According to the above table, the tax rate and quick calculation deduction corresponding to 1360 yuan are 3% and 0 respectively, so the individual income tax = 1360x3% - 0=40.8 yuan. In other words, in Guangzhou, the monthly salary of 6000 yuan needs to pay 40.8 yuan of personal income tax. Although only 4000 yuan was actually obtained, at least we know "the less money" Almost all of them are used to pay five insurances and one fund, and only a small part is used to pay personal tax.

If the salary does not exceed 7662, the five insurances and one fund will be calculated according to 20% of the salary. If the salary exceeds 7662, the five insurances and one fund will be calculated according to 766220%

Five insurances and one fund

Pension: 20% for units and 8% for individuals.

Unemployment: Unit 2%, individual 1%.

Medical treatment: unit 6-4%, individual 2-4%.

Industrial injury: Unit 1%, individual 0%.

Fertility: Unit 1%, individual 0%.

Local may change slightly.

A gold is generally 8% - 12% for units, and the same for individuals.

Tags: Javascript ECMAScript

Posted on Wed, 03 Nov 2021 23:42:56 -0400 by robsgaming