Share
Explore

# Learning TypeScript:Learning TypeScript:

Start by studying this Lab Sheet:

// Exercise 1
console.log("Hello World!");

// Exercise 2
for (let i = 1; i <= 10; i++) {
console.log(i);
}

// Exercise 3
function multiplyByTwo(num) {
return num * 2;
}

// Exercise 4
function sumOfArray(arr) {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum;
}

// Exercise 5
function largerNumber(num1, num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}

// Exercise 6
function reverseArray(arr) {
let reversedArray = [];
for (let i = arr.length - 1; i >= 0; i--) {
reversedArray.push(arr[i]);
}
return reversedArray;
}

// Exercise 7
function concatStrings(str1, str2) {
return str1 + str2;
}

// Exercise 8
function removeVowels(str) {
let newStr = '';
for (let i = 0; i < str.length; i++) {
if (str[i] !== 'a' && str[i] !== 'e' && str[i] !== 'i' && str[i] !== 'o' && str[i] !== 'u') {
newStr += str[i];
}
}
return newStr;
}

// Exercise 9
function largestNumber(arr) {
let largest = arr[0];
for (let i = 0; i < arr.length; i++) {
if (arr[i] > largest) {
largest = arr[i];
}
}
return largest;
}

// Exercise 10
function findCommonProperties(obj1, obj2) {
let commonProps = [];
for (let prop in
obj1) {
if (obj2.hasOwnProperty(prop)) {
commonProps.push(prop);
}
}
return commonProps;

# TypeScript Lesson Plan

This lesson plan outlines ten exercises in increasingly difficult order to teach college students how to write TypeScript, along with their corresponding solutions.

## Exercise 1

Instructions: Open the TypeScript playground, and enter a simple statement like “console.log("Hello World!");” and run it.
Solution: The output of the program should be “Hello World!”.

## Exercise 2

Instructions: Use the text editor to create a simple program that prints the numbers 1-10.
Solution: The program should print the numbers 1-10 in order, such as “1 2 3 4 5 6 7 8 9 10”.

## Exercise 3

Instructions: Create a simple function that takes a number as an argument and prints out the number multiplied by two.
Solution: The function should take a number as an argument,
provide the javascript code to solution these questions
```javascript
// Exercise 1
console.log("Hello World!");

// Exercise 2
for (let i = 1; i <= 10; i++) {
console.log(i);
}

// Exercise 3
function multiplyByTwo(num) {
return num * 2;
}

// Exercise 4
function sumOfArray(arr) {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum;
}

// Exercise 5
function largerNumber(num1, num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}

// Exercise 6
function reverseArray(arr) {
let reversedArray = [];
for (let i = arr.length - 1; i >= 0; i--) {
reversedArray.push(arr[i]);
}
return reversedArray;
}

// Exercise 7
function concatStrings(str1, str2) {
return str1 + str2;
}

// Exercise 8
function removeVowels(str) {
let newStr = '';
for (let i = 0; i < str.length; i++) {
if (str[i] !== 'a' && str[i] !== 'e' && str[i] !== 'i' && str[i] !== 'o' && str[i] !== 'u') {
newStr += str[i];
}
}
return newStr;
}

// Exercise 9
function largestNumber(arr) {
let largest = arr[0];
for (let i = 0; i < arr.length; i++) {
if (arr[i] > largest) {
largest = arr[i];
}
}
return largest;
}

// Exercise 10
function findCommonProperties(obj1, obj2) {
let commonProps = [];
for (let prop in
complete the solution for exercise 10
obj1) {
if (obj2.hasOwnProperty(prop)) {
commonProps.push(prop);
}
}
return commonProps;
create a lesson sheet showing how to make Objects in TypeScript. present 10 example

# TypeScript Objects

Objects are an important part of programming and are used to store and organize data. In TypeScript, objects can be created in two different ways: with object literals, and with the constructor approach.

## Object Literals

Objects literals are the simplest way to create an object in TypeScript. An object literal is created using curly braces, and the values and keys are separated using colons.

### Examples

let user = { name: 'John', age: 25 };

let car = {
make: 'Honda',
model: 'Accord',
year: 2020
}

let person = {
name: 'Jane',
age: 30,
street: '12 Main St',
city: 'New York',
state: 'NY'
}
}

let employee = {
id: 12345,
name: 'Susan',
position: 'Manager',
department: 'Marketing'
}

let product = {
id: 'ABC123',
name: 'iPhone 11',
price: 999.99
}

## Constructor Approach

Objects can also be created using a constructor function. This approach allows for more flexibility, as the constructor can be reused to create multiple objects with the same properties.

### Examples

class Person {
name: string;
age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
}
let person1 = new Person('John', 25);
let person2 = new Person('Jane', 30);

```