Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Coding Style#174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tunggnu merged 25 commits intojavascript-tutorial:masterfromImVietnam:patch-2
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
9bad668
Update article.md
ImVietnamFeb 21, 2023
73b0c53
Update code-style.svg
ImVietnamFeb 22, 2023
8e42191
Update code-style.svg
ImVietnamFeb 22, 2023
25c1521
Update code-style.svg
ImVietnamFeb 22, 2023
f1a0a9d
Update code-style.svg
ImVietnamFeb 22, 2023
e5e830a
Update code-style.svg
ImVietnamFeb 22, 2023
8899520
Update code-style.svg
ImVietnamFeb 22, 2023
fa1734b
Update code-style.svg
ImVietnamFeb 22, 2023
7368691
Update code-style.svg
ImVietnamFeb 22, 2023
185584c
Update code-style.svg
ImVietnamFeb 22, 2023
6e7a504
Merge pull request #2 from ImVietnam/patch-4
ImVietnamFeb 22, 2023
631b353
Update article.md
ImVietnamFeb 22, 2023
b44d40c
Update task.md
ImVietnamFeb 22, 2023
e6080c4
Update solution.md
ImVietnamFeb 22, 2023
ab3fc90
Merge pull request #3 from ImVietnam/patch-4
ImVietnamFeb 22, 2023
7787c62
Update solution.md
ImVietnamFeb 25, 2023
1375bf1
Update task.md
ImVietnamFeb 25, 2023
7da2573
Update article.md
ImVietnamFeb 25, 2023
87d1b13
Update article.md
ImVietnamMar 1, 2023
6c7aaae
Merge branch 'javascript-tutorial:master' into patch-2
ImVietnamJun 7, 2023
b41d273
Update solution.md
ImVietnamJun 8, 2023
b05925b
Update task.md
ImVietnamJun 8, 2023
1b00f35
Update article.md
ImVietnamJun 8, 2023
3b73fe3
Update article.md
ImVietnamJun 8, 2023
917bbe5
Merge branch 'javascript-tutorial:master' into patch-2
ImVietnamJun 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions1-js/03-code-quality/02-coding-style/1-style-errors/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@

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

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

let x=prompt("x?",''), n=prompt("n?",'') // <--technically possible,
//but better make it 2 lines, also there's no spaces and missing ;
if (n<=0) // <-no spaces inside(n <= 0), and should be extra line above it
{// <-figure bracket on a separate line
//below - long lines can be split into multiple lines for improved readability
alert(`Power${n}is not supported, please enter an integer number greater than zero`);
let x=prompt("x?",''), n=prompt("n?",'') // <--có thể trên lý thuyết,
//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 ;
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ó
{ // <-dấu ngoặc trên một dòng riêng biệt
//bên dưới - các dòng dài có thể được chia thành nhiều dòng để dễ đọc hơn
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`);
}
else // <-could write it on a single line like "} else {"
else // <-có thể viết nó trên một dòng như "} else {"
{
alert(pow(x,n)) //no spaces and missing ;
alert(pow(x,n)) //không có dấu cách và thiếu ;
}
```

The fixed variant:
Biến thể cố định:

```js
function pow(x, n) {
Expand All@@ -40,8 +40,8 @@ let x = prompt("x?", "");
let n = prompt("n?", "");

if (n <= 0) {
alert(`Power${n}is not supported,
please enter an integer number greater than zero`);
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`);
} else {
alert( pow(x, n) );
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ importance: 4

# Bad style

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

```js no-beautify
function pow(x,n)
Expand All@@ -17,12 +17,12 @@ function pow(x,n)
let x=prompt("x?",''), n=prompt("n?",'')
if (n<=0)
{
alert(`Power${n}is not supported, please enter an integer number greater than zero`);
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`);
}
else
{
alert(pow(x,n))
}
```

Fix it.
Hãy sửa nó.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp