Typescript Practice - Exercises 1. Enumerator: Pricelist (
Typescript Practice - Exercises 1. Enumerator: Pricelist (
Typescript Practice - Exercises 1. Enumerator: Pricelist (
1. Enumerator
enum PriceList{
"$23.50" = 1,
"$11.00",
"$36.99",
}
2. Types
var x = 3;
var y = 0;
var z = "Tony";
var a;
console.log(" x = 3: " + Boolean(x));
console.log(" x = 3 !x:" + Boolean(!x));
console.log(" y = 0: " + Boolean(y));
console.log(" z = Tony " + Boolean(z));
console.log(" z = Tony !z:" + Boolean(!z));
console.log("a " + Boolean(a));
console.log("a !a: " + Boolean(!a));
3. Functions
export
function conversion(x:number,y:string="f"):void{
if(y === "f"){
console.log((x-32) * 5 / 9 + " Celsius");
}
else if(y === "c"){
console.log((x * 9 / 5 + 32) + " Fahrenheit");
}
else{
console.log("Sorry, this conversion is not supported");
}
}
conversion(100,"c");
4. Class
export
class Automobile{
make:string;
model:string;
color:string;
mileage:number;
rating:number;
constructor(myMake:string, myModel:string, myColor:string, myMileage:number,
myRating:number){
this.make = myMake;
this.model = myModel;
this.color = myColor;
this.mileage = myMileage;
this.rating = myRating;
}
get intensity():number{
return this._intensity;
}
set intensity(x:number){
this._intensity = x;
}
}
xyz.color = "blue";
xyz.intensity = 8;
console.log(xyz.intensity);