Exercise-9 MST Programs
Exercise-9 MST Programs
9.a
Course Name: Typescript
Module Name: Basics of TypeScript
Aim: On the page, display the price of the mobile-based in three different colors.
Instead of using the number in our code, represent them by string values like
GoldPlatinum, PinkGold, SilverTitanium.
Procedure Steps:
Step 1: Create your directory Typescript in D:/> and change your directory
and Open the Text editor and create a file btscript.ts
Step 2: Install TypeScript using Node.js Package Manager (npm). Open a Node.js
command prompt and use the following command:
D:/Typescript> npm i –g typescript
Step 3: To verify the Typescript installation, run the following command:
D:/Typescript> tsc –v
Step 4: Run the Initialization command in that command prompt to create the necessary
configuration file for your project use the following command:
D:/Typescript> tsc --init
Step 5: Compile the TypeScript code. To compile the source code, open the Node.js
command prompt, and use the following command :
D:/Typescript> tsc btscript.ts
The above command converts the btscript.ts file into btscript.js file . It can easily
run in a Browser or Nodejs.
Step 6: Download a mobile image, and create a file mobile.html and btscript.js file is
embedded into mobile.html and run mobile.html file by the Browser then output
will be displayed.
9.a OUTPUT:
9.b
Course Name: Typescript
Module Name: Function
AIM: Define an arrow function inside the event handler to filter the product
array with the selected product object using the productId received by the
function. Pass the selected product object to the next screen.
exp9b.html
<!DOCTYPE html>
<html>
<head>
<title>Design a HTML page </title>
<script type="text/javascript" src="fun.js">
</script>
</head>
<body bgcolor="pink">
<center>
<img src="SamsungGalaxy_Gold.jpg" width="400px" height="360px" >
<h1><font color="red">Samsung Galaxy J7</font></h1>
</body>
</html>
9.b OUTPUT:
9.c
Course Name: Typescript
Module Name: Parameter Types and Return Types
AIM: Consider that developer needs to declare a function - getMobileByVendor
which accepts string as input parameter and returns the list of mobiles.
9.c OUTPUT:
9.d
Course Name: Typescript
Module Name: Arrow Function
AIM: Consider that developer needs to declare a manufacturer's array
holding 4 objects with id and price as a parameter and needs to implement an
arrow function - myFunction to populate the id parameter of manufacturers
array whose price is greater than or equal to 200 dollars .
9.d OUTPUT:
9.e
Course Name: TypeScript
Module Name: Optional and Default Parameters
AIM: Declare a function - getMobileByManufacturer with two parameters
namely manufacturer and id, where manufacturer value should passed as
Samsung and id parameter should be optional while invoking the function, if id
is passed as 101 then this function should return Moto mobile list and if
manufacturer parameter is either Samsung/Apple then this function should
return respective mobile list and similar to make Samsung as default
Manufacturer.
9.e OUTPUT: