Share
Explore

# 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