web123456

Day 4 of JavaScript

JavaScriptof the fourth day of the

assignment operator

*+= -= = /= %= assignment operator
在这里插入图片描述

unary operator (math.)

1. Both pre-increment and post-increment add one to themselves when they are not involved in an operation
在这里插入图片描述
running result
在这里插入图片描述
2. Participate in the operation, the front self-increment is first itself plus one, in the participation of the operation
Posterior self-increment is the first to participate in the operation, adding to itself a
在这里插入图片描述
running result
在这里插入图片描述
在这里插入图片描述
running result
在这里插入图片描述
Minor cases (a little brainstorming)
1.Code
在这里插入图片描述
2.Code Parsing
1) m is the occurrence of the self-incrementing operator plus one ...m=6
2) n is Posterior Self-Incrementing, first participates in the operation (assigns a value to n) and adds one to itself (m)... n=3 m=4
3) Posterior self-increment, to the other side of the budget note, itself plus one
m++ in k is equivalent to 4++ , and when it reaches the + side, it automatically adds one, at which point m = 5
++m is then equal to ++5
++56 is equivalent to the assignment operation and then adding 6, i.e. 66=36
4++ is a backward operation, first operation i.e. 4+36=40
At this point k=40
3. Arithmetic results
在这里插入图片描述

operator priority

The logical non-priority inside the unary operator is very high
Logical and has higher priority than logical or

1. Practice questions
在这里插入图片描述
2. Arithmetic results
在这里插入图片描述

3. Parsing
c false …!c true
b true
a false
First with operations then non-budget ... b&&a false
!c || false …true

breakpoint debugging

在这里插入图片描述

while loop

A loop is the repetitive execution of a piece of code until the condition is not met, ending the execution
while (loop condition) {
Loop body When the loop condition is true, the loop will keep executing When it is false, the loop will end.
}

在这里插入图片描述
2. Running results
在这里插入图片描述

Exercise 1

Page output 1-100
在这里插入图片描述

Exercise 2

Calculates the sum from 1 to 100 and outputs it
在这里插入图片描述

Exercise 3

Calculate all even sums from 1-100
在这里插入图片描述

Exercise 4

The page pops up a dialog box, 'Do you love me', if you enter 'love', it ends, otherwise it keeps popping up the dialog box
在这里插入图片描述

do-while loop

do{
Loop body First execute the loop body inside the do once, and then to determine the loop conditions, if the conditions are true, the loop body continues to execute.
If the condition is false, the loop ends.
}while (loop condition)

Find the sum of 1-100
在这里插入图片描述
The page pops up a dialog box, 'Do you love me', if you enter 'love', it ends, otherwise it keeps popping up the dialog box
Special case Don't add a let to declare a variable here, because if you add a let to declare a variable, it won't take effect outside the curly braces.
在这里插入图片描述

for loop

for (start value of variable, loop condition, change value of variable){
loop body
order of execution
1. Starting values of variables
2. Judge the loop condition, the loop condition is true, execute the loop body.
3. Variable change value...Judgment loop condition...Loop body
4. If the loop condition is false, the loop ends.
Note: the starting value of the variable, which is executed only once
}

1. Use for loop to output 1~100 years old
在这里插入图片描述
2. Find the average of all numbers between 1 - 100 Sum of 1 - 100 / 100
在这里插入图片描述
running result
在这里插入图片描述

3. find the sum of all even and odd numbers between 1 and 100
在这里插入图片描述
running result
在这里插入图片描述
4. Find the sum of all numbers between 1 and 100 that are divisible by 3.
在这里插入图片描述
running result
在这里插入图片描述

for loop nesting

The external loop controls the number of times the loop is executed inside
for (start value of outer loop; loop condition; variable change value) {
The inner loop controls the number of times the loop body is executed
for (start value of inner loop; loop condition; variable change value) {
loop body
}
Print 5 rows and 5 columns of stars
在这里插入图片描述
running result
在这里插入图片描述
Print positive triangles
在这里插入图片描述
running result
在这里插入图片描述
multiplication table
The second for loop is the multiplication table displayed horizontally, not vertically, so the first should be i, you need to change the
j changes its value in the outer nesting and remains unchanged in the inner nested loop.
Therefore the output is displayed horizontally with i written first在这里插入图片描述
Setting up a bit of css styling span is an in-line element that translates to
In-line block elements*
(at first converted to look at the block-level elements, each exclusive line, thought it was some kind of bug, doubt their ability to find bugs ... heart tired)
在这里插入图片描述
running result
在这里插入图片描述

cyclic interruption

continue: end the loop and continue to the next loop.
break: break out of the loop

Find the sum between 1 and 100, from the first to the sixth, that is divisible by 3.
在这里插入图片描述
running result
在这里插入图片描述

Difference between the three cycles

The for statement and the while statement are completely interchangeable. The syntax of the for statement is more concise, so the for loop is used more often.
If there is a conditional judgment involved, it is more appropriate to use while.
When it comes to counting the number of times it's easier to use for, the syntax is much simpler and straightforward
The do-while loop body is used at least once if some code must be executed once.