Skip to content

Commit e3c98c3

Browse files
committed
Add exercises
1 parent eaa5b66 commit e3c98c3

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Exercises.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Exercises
2+
3+
## Identifiers
4+
5+
1. Define variable to store your name as a string.
6+
2. Define constant to store your birth year as a number.
7+
3. Prepare function to print greeting with single argument.
8+
4. Call function passing value as literal.
9+
5. Call function passing variable.
10+
6. Call function passing constant.
11+
12+
## Loop
13+
14+
1. Print all odd numbers from the range [15, 30] including endpoints.
15+
2. Implement function `range(start: number, end: number)` doing the same task.
16+
17+
## Function
18+
19+
1. Implement function `average` with signature
20+
`average(a: number, b: number): number` calculating average (arithmetic mean).
21+
2. Implement function `square` with signature
22+
`square(x: number): number` calculating square of x.
23+
3. Implement function `cube` with signature
24+
`cube(x: number): number` calculating cube of x.
25+
4. Call functions `square` and `cube` in loop, then pass their results to
26+
function `average`. Print what `average` returns.
27+
28+
## Object
29+
30+
1. Define constant object with single field `name`.
31+
2. Define variable object with single field `name`.
32+
3. Try to change field `name` and assign other object to both identifiers.
33+
Explain script behaviour.
34+
4. Implement function `createUser` with signature
35+
`createUser(name: string, city: string): object`. Example:
36+
`createUser('Marcus Aurelius', 'Roma')` will return object
37+
`{ name: 'Marcus Aurelius', city: 'Roma' }`
38+
39+
## Array
40+
41+
1. Define array of objects with two fields: `name` and `phone` (phone book).
42+
Example: `{ name: 'Marcus Aurelius', phone: '+380445554433' }`.
43+
2. Implement function `findPhoneByName` with signature
44+
`findPhoneByName(name: string): string`. Returning phone from that object
45+
where field `name` equals argument `name`. Use `for` loop for this search.
46+
47+
## Hash
48+
49+
1. Define hash with `key` contains `name` (from previous example) and `value`
50+
contains `phone`.
51+
2. Implement function `findPhoneByName` with signature
52+
`findPhoneByName(name: string): string`. Returning phone from hash/object.
53+
Use `hash[key]` to find needed phone.

0 commit comments

Comments
 (0)