- 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): arrayreturning 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
averagewith signatureaverage(a: number, b: number): numbercalculating average (arithmetic mean). - Implement function
squarewith signaturesquare(x: number): numbercalculating square of x. - Implement function
cubewith signaturecube(x: number): numbercalculating cube of x. - Call
squareandcubein loop 0 to 9, pass results to functionaverageon 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
createUserwith 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:
nameandphone. Object example:{ name: 'Marcus Aurelius', phone: '+380445554433' }. - Implement function
findPhoneByNamewith signaturefindPhoneByName(name: string): string. Returning phone from that object where fieldnameequals argumentname. Useforloop for this search. A. Implement phone book using hash (also known asobject). - Define hash with
keycontainsname(from previous example) andvaluecontainsphone. - Implement function
findPhoneByNamewith signaturefindPhoneByName(name: string): string. Returning phone from hash/object. Usehash[key]to find needed phone.