add beginner code with
This commit is contained in:
parent
ca5807d864
commit
16f790a9d9
145
src/index.ts
145
src/index.ts
|
@ -1,3 +1,146 @@
|
||||||
|
interface People {
|
||||||
|
name: string;
|
||||||
|
age: number | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let people01: People = {
|
||||||
|
name: "Kostya",
|
||||||
|
age: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
let people02: People = {
|
||||||
|
name: "Yura",
|
||||||
|
age: 32
|
||||||
|
}
|
||||||
|
|
||||||
|
people01.age = 60;
|
||||||
|
// console.log(people01);
|
||||||
|
// console.log(JSON.stringify(people01));
|
||||||
|
// console.log(people01.age);
|
||||||
|
console.log(`${people01.name} имеет возраст ${people01?.age ?? '40'}`); //Kostya --- 60
|
||||||
|
console.log(`${people02.name} имеет возраст ${people02?.age ?? '40'}`); //Yura --- 32
|
||||||
|
console.log(`${people01.name} имеет возраст ${people02?.age ?? '40'}`);
|
||||||
|
|
||||||
|
interface PeopleLocation extends People {
|
||||||
|
location: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let peopleLocation01: PeopleLocation = {
|
||||||
|
name: "djdf",
|
||||||
|
age: 42342,
|
||||||
|
location: "dafdf"
|
||||||
|
}
|
||||||
|
class ProcessingPeoples implements PeopleLocation {
|
||||||
|
name: string;
|
||||||
|
age: number | undefined;
|
||||||
|
location: string = '';
|
||||||
|
|
||||||
|
constructor(name: string){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProcessingPeoplesExt extends ProcessingPeoples {
|
||||||
|
isActive: boolean = false;
|
||||||
|
|
||||||
|
constructor(name: string, isActive: boolean){
|
||||||
|
super(name);
|
||||||
|
if(isActive) {
|
||||||
|
this.location = 'Gorkyi street';
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.location = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let a: ProcessingPeoples = new ProcessingPeoplesExt("Vasya", true);
|
||||||
|
|
||||||
|
class Duck {
|
||||||
|
type: string = 'Duck';
|
||||||
|
weight: number = 0;
|
||||||
|
log(){
|
||||||
|
console.log("I'm simple duck");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Eateable {
|
||||||
|
eat(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
class GreyDuck extends Duck implements Eateable{
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.type = 'GreyDuck'
|
||||||
|
}
|
||||||
|
override log(){
|
||||||
|
console.log("I'm grey duck");
|
||||||
|
}
|
||||||
|
|
||||||
|
eat(){
|
||||||
|
console.log("I'm eat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RedDuck extends Duck implements Eateable {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.type = 'RedDuck'
|
||||||
|
}
|
||||||
|
eat(): void {
|
||||||
|
console.log("I'm eat");
|
||||||
|
}
|
||||||
|
override log(){
|
||||||
|
console.log("I'm red duck");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let duck1 = new RedDuck();
|
||||||
|
let duck2 = new GreyDuck();
|
||||||
|
|
||||||
|
let array: Eateable[] = [
|
||||||
|
duck1,
|
||||||
|
duck2
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let item of array) {
|
||||||
|
item.eat();
|
||||||
|
}
|
||||||
|
|
||||||
|
let array2: Duck[] = [
|
||||||
|
duck2,
|
||||||
|
duck1
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let item of array2) {
|
||||||
|
item.log();
|
||||||
|
}
|
||||||
|
|
||||||
|
array2.filter(item => "eat" in item);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Обучение ЦИКЛАМ
|
//Обучение ЦИКЛАМ
|
||||||
|
|
||||||
//lesson 1.5 SUM OF NUMBERS
|
//lesson 1.5 SUM OF NUMBERS
|
||||||
|
@ -41,6 +184,8 @@ function SUMMA (chislo: number){
|
||||||
let result = 5;
|
let result = 5;
|
||||||
console.log(`summa of numbre <1000: ${result}`);
|
console.log(`summa of numbre <1000: ${result}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
function DrawLine(count: number, countP: number){ //рисуем треугольник из звездочек
|
function DrawLine(count: number, countP: number){ //рисуем треугольник из звездочек
|
||||||
const minimalString = '*';
|
const minimalString = '*';
|
||||||
|
|
Loading…
Reference in New Issue