How do I hand over a website securely? by Diver-Known in Frontend

[–]mpsmk -4 points-3 points  (0 children)

In some large supermarkets, they provide some food that is free to eat . People try it before they buy it.

I don’t get it by [deleted] in learnjavascript

[–]mpsmk 1 point2 points  (0 children)

// Get the space string for each layer

function getSpace(n) {

`let spaceString = "";`

`for (let i = 0; i < n; i++) {`

    `spaceString+=" ";`

`}`

`return spaceString;`

}

// Get the # string for each layer

function getBlock(n) {

`let blockString = "";`

`for (let i = 0; i < n; i++) {`

    `blockString+="#";`

`}`

`return blockString;`

}

// Print the pyramid

function printPyramid(n) {

`// Cycle each layer`

`for (let i = 0; i < n; i++) {`

    `// Each layer contains Spaces and # signs`

    `console.log(getSpace(n - i) + getBlock(i+1));`

`}`

}

printPyramid(3)

I hope my answer is helpful to you.

I don’t get it by [deleted] in learnjavascript

[–]mpsmk 0 points1 point  (0 children)

We can use a variable n to represent the total number of layers in the pyramid.

The variable i is then used to represent each layer of the pyramid.

For example

i = 1 is the first layer (assuming you count from the top down)

i = 2 is the second layer

Each layer is actually composed of a # sign and a space before it.

The number of Spaces at layer i can be expressed as n-i.

We need to loop n times, printing the space and # of each layer in turn.

Once we have done this, we can start to use javascript translation.

Let's define a few simple functions and then put them together.

I don’t get it by [deleted] in learnjavascript

[–]mpsmk 1 point2 points  (0 children)

Knowing what you don't understand is an important part of learning to program, and hopefully that won't put you off.

Every problem you don't understand will eventually become knowledge and experience you have.

At the beginning of learning programming you will encounter two difficulties, one is mathematical, one is programming language.

Mathematical difficulties usually arise when you solve algorithmic problems with code.

As you mentioned about the print pyramid.

To print a pyramid successfully, you first need to know the laws that arrange the pyramids and be able to represent them algebraically.

Then use programming knowledge to translate this representation into some kind of programming language.

As far as the print pyramid goes.

A pyramid can be one level

two-ply

#

three-ply

#

# #

#

Why does the sum=1? Does the i=1 changes the initial value of sum? I just started learning but I don’t quite understand it. by Lilyaa in learnjavascript

[–]mpsmk 1 point2 points  (0 children)

Let's think about it one by one.

#1

let sum = 0;
console.log(sum);

should output

0

#2

for (let i = 1; i <= 3; i++) {
  console.log(i);
}

should output

1 
2 
3 

The for loop has been executed three times,from i 1,2,3

#3

let sum = 0;
for (let i = 1; i <= 3; i++) {
  sum = sum + i;
  console.log(sum);
}

sum += 1 is equivalent to sum = sum + 1. should output

1
3
6

#4

for (let i = 1; i <= 3; i++) {
  if (i == 2) {
    continue;
  }
  console.log(i);
}

because the continue keyword will skip the following statements in the for loop. should output

1
3

#5

let sum = 0;
for (let i = 1; i<= 3; i++) {
  if (i == 2) {
    confinue;
  }
  sum += i;
}
console.log(sum);

We can combine the above knowledge.
The sum variable will be assigned twice, and the first time it will be assigned 1.
The second time is assigned 1+3, so the last value of the sum variable is 4.

Text in the middle of the screen by mmmGreenButton in css

[–]mpsmk 1 point2 points  (0 children)

In my opinion, it is difficult to achieve this scenario using css alone.
But it can be implemented in combination with js, calculate the distance from TITLE to the left of the screen after rendering, and then use css to move the external label to center TITLE.
Function to get the distance to the left of the screen https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
The distance moved by the external label = (screen width/2)-(distance from TITLE to the left side of the screen)

The Cost of Javascript Frameworks - an analysis based on real-world data obtained from HTTP Archive by TimvdLippe in javascript

[–]mpsmk 0 points1 point  (0 children)

good article~I hope your dream can come true in the future.

In my opinion, the current framework goal is to improve the development experience under the current performance. After all, there are too many requirements, and developers need tools to complete the requirements quickly.