Repository navigation
Expand file tree
/
Copy pathlesson-12.js
More file actions
137 lines (102 loc) · 3.31 KB
/
Copy pathlesson-12.js
File metadata and controls
137 lines (102 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Lesson 12. 1. Method chaining JavaScript
// Вызов методов один за другим, на одной линии
// let fullName = 'sheroz samatov';
// let letter = fullName.slice(0, fullName.indexOf(" ")).toUpperCase().charAt(0);
// console.log(letter);
// 2. Javascript checked method to check if the checkbox and radio buttons are checked or not
// document.getElementById("myButtom").onclick = function() {
// const myCheckbox = document.getElementById("myCheckbox");
// const visaBtn = document.getElementById("visaBtn");
// const mastercardBtn = document.getElementById("mastercardBtn");
// const paypalBtn = document.getElementById("paypalBtn");
// if(myCheckbox.checked) {
// console.log('You are subscribed!');
// }
// else {
// console.log('You are NOT subscribed!');
// }
// if(visaBtn.checked) {
// console.log('You are paying with VISA!');
// }
// else if(mastercardBtn.checked) {
// console.log('You are paying with Mastercard!');
// }
// else if(paypalBtn.checked) {
// console.log('You are paying with PayPal!');
// }
// else {
// console.log('You must select a payment type!');
// }
// }
// 3. Javascript nested for loops.
// Цикл внутри цикла, т.е. for внутри for
// for (let i = 1; i <= 3; i++) {
// console.log('в каждой итерации i равно: ', i);
// for (let j = 1; j <= 3; j++) {
// console.log('в каждой итерации i, j равно: ', j);
// }
// }
// for (let i = 1; i <= 3; i++) {
// for (let j = 1; j <= 3; j++) {
// console.log(i, j);
// }
// }
// let row = 4;
// let column = 5;
// for (let i = 1; i <= row; i++) {
// for (let j = 1; j <= column; j++) {
// console.log(i, j);
// }
// }
// Example 1. How to print a rectangle in the Page, DOM method.
// let row = prompt('Enter a number of rows: ');
// let column = prompt('Enter a number of columns: ');
// for (let i = 1; i <= row; i++) {
// for (let j = 1; j <= column; j++) {
// // let a = document.getElementById("myRectangle").innerHTML;
// // a += '*'; // a = a + '*'
// document.getElementById("myRectangle").innerHTML += '*';
// }
// document.getElementById("myRectangle").innerHTML += '<br>';
// }
// Example 2. How to print a rectangle in the console with a function
// printRectangle(4, 10);
// function printRectangle(row, column) {
// let string = '';
// for (let i = 1; i <= row; i++) {
// for (let j = 1; j <= column; j++) {
// string += '*';
// }
// string += "\n";
// }
// console.log(string);
// }
// Example 3. How to print a left triangle in JavaScript
// printTriangle(10)
// function printTriangle(number) {
// let string = '';
// for (let i = 1; i <= number; i++) {
// for (let j = 0; j < i; j++) {
// string += '*';
// }
// string += "\n";
// }
// console.log(string);
// }
// Examle 4. How to print a right trianle in JavaScript
// printTriangle(15)
// function printTriangle(number) {
// let string = '';
// for (let i = 1; i <= number; i++) {
// // for loop to print spaces
// for (let j = 0; j < number - i; j++) {
// string += ' ';
// }
// // for loop to print the '*'
// for(let k = 0; k < i; k++) {
// string += '*';
// }
// string += '\n'
// }
// console.log(string);
// }