- Define variable to store your name as a string.
- Define constant to store your birth year as a number.
- Prepare function to print greeting with single argument.
- Implement function
range(start: number, end: number): array
returning array with all numbers from the range [15, 30] including endpoints. - Implement function
rangeOdd(start: number, end: number)
returning array with all odd numbers from the range [15, 30] including endpoints.
- Call function from function in loop
- Implement function
average
with signatureaverage(a: number, b: number): number
calculating average (arithmetic mean). - Implement function
square
with signaturesquare(x: number): number
calculating square of x. - Implement function
cube
with signaturecube(x: number): number
calculating cube of x. - Call
square
andcube
in loop 0 to 9, pass results to functionaverage
on each iteration. Add calculation results to array and return this array from functioncalculate
.
Call functions square
and cube
in loop, then pass their results to
function average
. Print what average
returns.
- Do following tasks inside function
fn
(see stub:7-objects.js
)
- Define constant object with single field
name
. - Define variable object with single field
name
. - Try to change field
name
. - Try to assign other object to both identifiers.
- Explain script behaviour.
- Implement function
createUser
with signaturecreateUser(name: string, city: string): object
. Example:createUser('Marcus Aurelius', 'Roma')
will return object{ name: 'Marcus Aurelius', city: 'Roma' }
- Implement phone book using array of records.
- Define Array of objects with two fields:
name
andphone
. Object example:{ name: 'Marcus Aurelius', phone: '+380445554433' }
. - Implement function
findPhoneByName
with signaturefindPhoneByName(name: string): string
. Returning phone from that object where fieldname
equals argumentname
. Usefor
loop for this search. A. Implement phone book using hash (also known asobject
). - Define hash with
key
containsname
(from previous example) andvalue
containsphone
. - Implement function
findPhoneByName
with signaturefindPhoneByName(name: string): string
. Returning phone from hash/object. Usehash[key]
to find needed phone.