Skip to content

Instantly share code, notes, and snippets.

//Assignment #1
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 {
//Assignment #2
//Task1
//Create class
class Person {
firstName: string;
lastName: string;
}
//Create instance 1
const person1 = new Person();
//Assignment #2
//Task1
//Create class
class Person {
firstName: string;
lastName: string;
}
//Create instance 1
const person1 = new Person();
//Assignment #1
class Calculator {
// for static methods no need to create a new instance
static additionReturnNumber(num1: number, num2: number): number {
return num1 + num2;
}
static additionReturnString(num1: number, num2: number): string {
const resultNum: number = num1 + num2;
import { HomeWork } from '../src/homework'
import { multiplication, calculatePercentage, isEven, stringComparison, isPositive } from '../src/homework'
describe('HomeWork Class testing', () => {
let operation: HomeWork;
test('should multiply two numbers correctly', () => {
operation = new HomeWork();
expect(operation.multiplication(2, 3)).toBe(6);
})
import { User } from '../src/user';
test("should be able to give consent",() => {
const user = new User( "Will", "Doe", 19);
user.giveConsent();
expect(user.getConsent()).toBeTruthy();
})
test("should not be able to give consent",() => {
const user = new User( "Jane", "Doe", 18);
export class BaseContract {
contractId: string;
clientName: string;
isActive: boolean;
constructor(contractId: string, clientName: string, isActive: boolean) {
this.contractId = contractId;
this.clientName = clientName;
this.isActive = isActive;
}
// length property tells how many elements are inside the array
let fruits = ["apple", "banana", "orange"];
console.log(fruits.length);
// push() method: adds a new element to the end of the array
fruits = ["apple", "banana"];
fruits.push("orange");
console.log(fruits.length);
// pop() method: removes the last element from the array