Skip to content

Commit 82cf1b9

Browse files
committed
tweaks 9c
1 parent 16537b1 commit 82cf1b9

File tree

4 files changed

+126
-73
lines changed

4 files changed

+126
-73
lines changed

src/content/9/en/part9b.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,29 @@ In the example, the <i>first argument</i> is the target value.
563563
564564
Handle exceptions and errors appropriately. The exerciseCalculator should accept inputs of varied lengths. Determine by yourself how you manage to collect all needed input.
565565
566+
Cople of things to notice:
567+
568+
If you define helper functions in other modules, you should use the [JavaScript module system](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), that is, the one we have used with React where importing is done with
569+
570+
```js
571+
import { isNotNumber } from "./utils";
572+
```
573+
574+
and exporting
575+
576+
```js
577+
export const isNotNumber = (argument: any): boolean =>
578+
isNaN(Number(argument));
579+
580+
default export "this is the default..."
581+
```
582+
583+
Another note: somehow surprisingly TypeScript does not allow to define the same variable in many files at a "block-scope", that is, outside functions (or classes):
584+
585+
![browser showing pong from localhost:3000/ping](../../images/9/60new.png)
586+
587+
This is actually not quite true. This rule applies only to files that are treated as "scripts". A file is a script if it does not contain any export or import statements. If a file has those, then the file is treated as a [module](https://www.typescriptlang.org/docs/handbook/modules.html), <i>and</i> the variables do not get defined in the block-scope.
588+
566589
</div>
567590
568591
<div class="content">
@@ -1057,7 +1080,7 @@ Configure your project to use the above ESlint settings and fix all the warnings
10571080
10581081
#### 9.7 WebExercises
10591082
1060-
Add an endpoint to your app for the exercise calculator. It should be used by doing an HTTP POST request to endpoint <i>exercises</i> with the input in the request body:
1083+
Add an endpoint to your app for the exercise calculator. It should be used by doing an HTTP POST request to endpoint http://localhost:3002/exercises with the input in the request body:
10611084
10621085
```js
10631086
{

0 commit comments

Comments
 (0)