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

Commit d3d8d83

Browse files
committed
Refactor number formatting and rounding in article.md
1 parent 7e88742 commit d3d8d83

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
21
```js run demo
32
function readNumber() {
43
let num;
54

65
do {
7-
num = prompt("Enter a number please?", 0);
6+
num = prompt("กรุณาป้อนตัวเลข", 0);
87
} while ( !isFinite(num) );
98

109
if (num === null || num === '') return null;
1110

1211
return +num;
1312
}
1413

15-
alert(`Read: ${readNumber()}`);
14+
alert(`อ่านค่า: ${readNumber()}`);
1615
```
1716

18-
The solution is a little bit more intricate that it could be because we need to handle `null`/empty lines.
19-
20-
So we actually accept the input until it is a "regular number". Both `null` (cancel) and empty line also fit that condition, because in numeric form they are `0`.
17+
วิธีแก้ปัญหานี้ค่อนข้างซับซ้อนกว่าที่ควรจะเป็นเล็กน้อย เพราะเราต้องจัดการกับ `null` และบรรทัดว่าง
2118

22-
After we stopped, we need to treat `null` and empty line specially (return `null`), because converting them to a number would return `0`.
19+
ดังนั้นเราจึงยอมรับการป้อนข้อมูลจนกว่าจะเป็น "ตัวเลขปกติ" ทั้ง `null` (ยกเลิก) และบรรทัดว่างก็เข้าเงื่อนไขนี้ด้วย เพราะในรูปแบบตัวเลขพวกมันเป็น `0`
2320

21+
หลังจากที่เราหยุด เราต้องจัดการกับ `null` และบรรทัดว่างเป็นพิเศษ (ส่งคืน `null`) เพราะการแปลงพวกมันเป็นตัวเลขจะส่งคืน `0`

‎1-js/05-data-types/02-number/3-repeat-until-number/task.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ importance: 5
22

33
---
44

5-
# Repeat until the input is a number
5+
# ทําซ้ําจนกว่าจะได้รับข้อมูลเป็นตัวเลข
66

7-
Create a function `readNumber` which prompts for a number until the visitor enters a valid numeric value.
7+
สร้างฟังก์ชัน `readNumber` ที่ขอให้ป้อนตัวเลขจนกว่าผู้เข้าชมจะป้อนค่าตัวเลขที่ถูกต้อง
88

9-
The resulting value must be returned as a number.
9+
ค่าที่ได้ต้องถูกส่งคืนเป็นตัวเลข
1010

11-
The visitor can also stop the process by entering an empty line or pressing "CANCEL". In that case, the function should return `null`.
12-
13-
[demo]
11+
ผู้เข้าชมสามารถหยุดกระบวนการได้โดยการป้อนบรรทัดว่างหรือกด "CANCEL" ในกรณีนั้น ฟังก์ชันควรส่งคืน `null`
1412

13+
[สาธิต]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /