Created
December 1, 2025 20:59
-
-
Save ikotse-code/60eab7c85d79c27d9b52876032b6e42e to your computer and use it in GitHub Desktop.
HW3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Assignment #2 | |
| //Task1 | |
| //Create class | |
| class Person { | |
| firstName: string; | |
| lastName: string; | |
| } | |
| //Create instance 1 | |
| const person1 = new Person(); | |
| person1.firstName = "Anna"; | |
| person1.lastName = "Miller"; | |
| console.log(person1.firstName, person1.lastName); | |
| console.log(person1); | |
| //Create instance 2 | |
| const person2 = new Person(); | |
| person2.firstName = "Bob"; | |
| person2.lastName = "Kuller"; | |
| console.log(person2.firstName, person2.lastName); | |
| console.log(person2); | |
| //Task2 | |
| //Create class | |
| class Book { | |
| title: string; | |
| author: string; | |
| pages: number; | |
| constructor(title: string, author: string, pages: number) { | |
| this.title = title; | |
| this.author = author; | |
| this.pages = pages; | |
| } | |
| } | |
| //Create instance with values | |
| const book1 = new Book("ABC", "John Doe", 5); | |
| console.log(book1.title, book1.author, book1.pages); | |
| console.log(book1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Assignment #1 | |
| //Task1 | |
| function convertToFahrenheit (celsius: number):number { | |
| return ((celsius * 9 / 5) + 32); | |
| } | |
| function greetUser (firstName: string, lastName: string): string { | |
| return ("Hello, " + firstName + " " + lastName + "!"); | |
| } | |
| function calculateArea (width: number, height: number): number { | |
| return (width * height); | |
| } | |
| function addNumbers (a: number, b: number): number { | |
| return (a+b); | |
| } | |
| console.log(convertToFahrenheit(25)); | |
| console.log(greetUser("Anna", "Miller")); | |
| console.log(calculateArea(4,5)); | |
| console.log(addNumbers(10,15)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very well done, Irina! You write clean and readable code!