Skip to content

Commit 94a73bd

Browse files
authored
Merge pull request #174 from ImVietnam/patch-2
Coding Style
2 parents f3eb89b + 917bbe5 commit 94a73bd

File tree

4 files changed

+127
-128
lines changed

4 files changed

+127
-128
lines changed

Diff for: 1-js/03-code-quality/02-coding-style/1-style-errors/solution.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11

2-
You could note the following:
2+
Bạn có thể lưu ý những điều sau:
33

44
```js no-beautify
5-
function pow(x,n) // <- no space between arguments
6-
{ // <- figure bracket on a separate line
7-
let result=1; // <- no spaces before or after =
8-
for(let i=0;i<n;i++) {result*=x;} // <- no spaces
9-
// the contents of { ... } should be on a new line
5+
function pow(x,n) // <- không có khoảng cách giữa các đối số
6+
{ // <- dấu ngoặc đơn trên một dòng riêng biệt
7+
let result=1; // <- không có dấu cách trước hoặc sau dấu =
8+
for(let i=0;i<n;i++) {result*=x;} // <- không có dấu cách
9+
// nội dung của { ... } nên ở một dòng mới
1010
return result;
1111
}
1212

13-
let x=prompt("x?",''), n=prompt("n?",'') // <-- technically possible,
14-
// but better make it 2 lines, also there's no spaces and missing ;
15-
if (n<=0) // <- no spaces inside (n <= 0), and should be extra line above it
16-
{ // <- figure bracket on a separate line
17-
// below - long lines can be split into multiple lines for improved readability
18-
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
13+
let x=prompt("x?",''), n=prompt("n?",'') // <-- có thể trên lý thuyết,
14+
// nhưng tốt hơn là viết thành 2 dòng, cũng như không có dấu cách và thiếu ;
15+
if (n<=0) // <- không có khoảng trắng bên trong (n <= 0) và phải có thêm dòng phía trên nó
16+
{ // <- dấu ngoặc trên một dòng riêng biệt
17+
// bên dưới - các dòng dài có thể được chia thành nhiều dòng để dễ đọc hơn
18+
alert(`Luỹ thừa ${n} không được hỗ trợ, vui lòng nhập một số nguyên lớn hơn 0`);
1919
}
20-
else // <- could write it on a single line like "} else {"
20+
else // <- có thể viết nó trên một dòng như "} else {"
2121
{
22-
alert(pow(x,n)) // no spaces and missing ;
22+
alert(pow(x,n)) // không có dấu cách và thiếu ;
2323
}
2424
```
2525

26-
The fixed variant:
26+
Biến thể cố định:
2727

2828
```js
2929
function pow(x, n) {
@@ -40,8 +40,8 @@ let x = prompt("x?", "");
4040
let n = prompt("n?", "");
4141

4242
if (n <= 0) {
43-
alert(`Power ${n} is not supported,
44-
please enter an integer number greater than zero`);
43+
alert(`Luỹ thừa ${n} không được hỗ trợ,
44+
vui lòng nhập một số nguyên lớn hơn 0`);
4545
} else {
4646
alert( pow(x, n) );
4747
}

Diff for: 1-js/03-code-quality/02-coding-style/1-style-errors/task.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 4
44

55
# Bad style
66

7-
What's wrong with the code style below?
7+
Có gì sai với cách viết code này?
88

99
```js no-beautify
1010
function pow(x,n)
@@ -17,12 +17,12 @@ function pow(x,n)
1717
let x=prompt("x?",''), n=prompt("n?",'')
1818
if (n<=0)
1919
{
20-
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
20+
alert(`Luỹ thừa ${n} không được hỗ trợ, vui lòng nhập một số nguyên lớn hơn 0`);
2121
}
2222
else
2323
{
2424
alert(pow(x,n))
2525
}
2626
```
2727

28-
Fix it.
28+
Hãy sửa nó.

0 commit comments

Comments
 (0)