-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
438 lines (368 loc) · 7.94 KB
/
Copy pathmain.js
File metadata and controls
438 lines (368 loc) · 7.94 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
/*
var carName = "BMW";
var carSpeed = 60;
var hasAutomaticTransmission = true;
var car ;
//console.log(typeof car);
//console.log(a);
var fullName = 'Herbert Wels';
var firstName = fullName.substr(0, 7);
//console.log(firstName);
//console.log (fullName.indexOf('ber'));
var fullName1 = 'Jon Snow';
//console.log(fullName1[0] + '.' + fullName1[fullName1.indexOf('Sno')] + '.');
//console.log(fullName[0] + '.' + fullName[fullName.indexOf('Wel')] + '.');
var login = 'Jo';
var email = 'test';
var phone = '';
var firstRule = login.length >= 3 && login.length <= 20;
var secondRule = email.length > 0 || phone.length > 0;
var result = firstRule && secondRule;
//if (result)
// {console.log('valid');
//} else
//{ console.log('invalid');
// if (login.length < 3) {
// console.log('You have entered ' + login.length + ' characters. You should put more than 2 chars for login');
// }
// var phoneOrEmail = phone.length = 0 ? 'You should input phone' : 'You should pu email';
// console.log(phoneOrEmail);
//}
//var genre = 'cheap';
//switch(genre) {
// case 'cheap':
// console.log('reno, lanos');
// break;
// case 'premium':
// console.log('bmw, mersedes');
// break;
// default:
// console.log('hundai')
// break;
//}
var i=10;
var i = 0;
//while (i < 5) {
// console.log(i+=2);
// console.log('======');
//}
//var first = text.substr(0, text.indexOf(' ') - 1);
//var characNum = text.indexOf(' ');
//console.log(first);
//console.log(characNum);
//var second = text.substr(text.indexOf(' '));
//console.log(second);
var fullText = 'Javascript is very popular, creative, interest, famous language in wwweb world. You can read, test jsknights.';
var text = fullText;
var lessOrThreeChar = fourChar = fiveChar = sixOrMoreChar =0;
while (checkComa !=0) {
var indexComa = text.indexOf(',') == -1 ? text.indexOf('.') : text.indexOf(',');
var firstPart = text.substr(0, indexComa);
var secondPart = text.substr(indexComa+1);
var text = firstPart + secondPart;
var checkComa = indexComa == -1 ? 0 : 1;
}
while (finish != 0) {
var numSpace = text.indexOf(' ');
var word = numSpace == -1 ? text.substr(0) : text.substr(0, numSpace);
var text = text.substr(numSpace+1);
if (word.length <= 3) {
lessOrThreeChar++;
}
else {
if (word.length == 4) {
fourChar++;
}
else {
if (word.length == 5) {
fiveChar++;
}
else {
sixOrMoreChar++;
}
}
}
var finish = numSpace == -1 ? 0 : 1;
}
var totalWords = lessOrThreeChar + fourChar + fiveChar + sixOrMoreChar;
var lessOrThreeCharPercent = lessOrThreeChar / totalWords * 100;
var fourCharPercent = fourChar / totalWords * 100;
var fiveCharPercent = fiveChar / totalWords * 100;
var sixOrMoreCharPercent = sixOrMoreChar / totalWords * 100;
console.log(fullText);
console.log('Three or less words are ' + lessOrThreeChar + ' and it is ' + lessOrThreeCharPercent + '%');
console.log('Four words are ' + fourChar + ' and it is ' + fourCharPercent + '%');
console.log('Five words are ' + fiveChar + ' and it is ' + fiveCharPercent + '%');
console.log('Six or more words are ' + sixOrMoreChar + ' and it is ' + sixOrMoreCharPercent + '%');
*/
/*
var title = 'The time machine'
console.log(title.length);
*/
/*
var letters = 'ABC';
for (i = 0; i< letters.length; i++) {
// console.log(letters[i] + i);
var letter = letters[i];
for (j = 1; j< 4; j++) {
console.log(letter + j);
}
} */
/*
var text = 'Hello. Good. Buy. Awesome.Perfect.'
for (i =0; i< text.length; i++) {
var letter = text[i];
if (i%2 ==1) {
continue;
}
if (text[i] == '.') {
console.log(i);
break;
}
} */
/*
var cup = {
color: 'white',
size: 'big',
'coffe type': 'latte'
}
//console.log(cup.color, cup.size);
key = 'coffe type';
//console.log(cup['coffe type']);
//console.log(cup[key]);
cup['temperature']= 90;
console.log(cup);
console.dir(cup);
*/
/*
var book = {
title: 'time machine',
color: 'green',
author: {
name: 'Gerbert',
lastname: 'Wales',
country: {
lat: 50,
lon: 0
}
}
};
//console.log(book.author.country.lat, book['author']['country']['lon']);
//console.log(book);
for (var key in book.author) {
// console.log(key);
};
if ('title' in book) {
//console.log('key exists');
};
book.pageCount = 100;
delete book.pageCount;
//console.log(book.pageCount);
//console.log(book);
var album = {
size: 'big',
painting: 'yes'
};
//console.log(album);
var albook = book;
for (var key in album) {
albook[key] = album[key];
};
console.log(albook);
*/
/*
var names = ['John', 'Nina', 'Marina'];
names.push('Katie');
console.log(names);
names.pop();
console.log(names);
names.unshift('Baddy');
console.log(names);
names.shift();
console.log(names);
*/
/*
var names = ['John', 'Nina', 'Marina'];
for (i = 0; i< names.length; i++) {
if (names[i] == 'Nina') {
console.log('Nina has index', i);
break;
}
}
console.log('Nina has index', names.indexOf('Nina'));
names.splice(1, 1, 'Paul', 'Derek');
console.log(names);
*/
//var names = ['John', 'Nina', 'Derek', 'Marina'];
//var sliced = names.slice(1, 3);
//console.log(sliced);
/*
var namesString = ('John,Nina,Derek,Marina');
var names = namesString.split(',');
console.log(names);
var nam = names.join('|');
console.log(nam);
*/
/*
var friends = ['Katie', 'Bud'];
var neighbours = ['Mary', 'Andrew'];
var partyGuests = neighbours.concat(friends);
console.log(partyGuests);
friends[2] = 'James';
console.log(friends);
*/
/*
var names = ['John', 'Nina', 'Derek', 'Marina'];
names[4] = 'Bob';
names[10] = 'Rik';
for (var i = 0; i < names.length; i++) {
console.log(i, names[i]);
}
*/
/*
var names = ['Ann', 'Jone'];
names.color = 'green';
//console.log(names);
//console.log(names.color);
//names[50] = 'Bob';
//console.log(names);
for (key in names) {
console.log(key, names[key]);
}
console.log(names.length);
delete names[1];
console.log(names.length);
console.log(names);
*/
/*
var a = '4' - 3;
console.log(a);
*/
/*
var a = [];
if (a) {
console.log('True');
} else {
console.log('False');
}
*/
/*
function pron(name) {
if (name) {
console.log(name);
} else {
console.log('not valid');
}
}
pron('Johnny');
var bool = !!'a';
console.log(typeof bool);
console.log(bool);
*/
/*
var str = String(false);
console.log(str);
console.log(typeof(str));
*/
/*
function printHello() {
console.log('***********');
console.log('Hello There');
console.log('***********');
}
for (i=0; i<10; i++) {
printHello();
}
*/
/*
function adding(a, b) {
c = a+b;
console.log(a, '+', b, '=', c);
}
adding(5, 45);
*/
/*
function adding(a, b, c) {
return a+b+c;
}
var result = adding(4, 7, 3);
console.log(result);
*/
/*
var books = [
{
title: "Prelude to Foundation",
author: "Isaac Asimov",
numberOfPages: 512
},
{
title: "The Tomb of Atuan",
author: "Ursula K. Le Guin",
numberOfPages: 192
},
{
title: "Starship Troopers",
author: "Robert A. Heinlein",
numberOfPages: 263
}
];
//console.log(books.length);
function findBiggestBook(books) {
var book = null;
var maxPages = 0;
for (var i = 0; i < books.length; i++) {
if (books[i].numberOfPages > maxPages) {
var book = books[i];
var maxPages = books[i].numberOfPages;
}
}
return book;
}
//var theBiggestBook = findBiggestBook(books);
//console.log(theBiggestBook);
function findBookByTitle(name) {
var filtBook = [];
for (var i = 0; i < books.length; i++) {
var b = books[i].title;
var findTitle = b.indexOf(name);
if (findTitle > 0) {
filtBook.push(b);
//filtBook.push('b');
//console.log(b);
}
}
//return filtBook;
console.log(filtBook);
}
findBookByTitle('h');
*/
/*
function add(a, b, c) {
console.log(a, b, c);
console.log(arguments[3], arguments[4]);
return a + b + c;
}
var result = add(1, 2, 3, 4, 5);
console.log(result);
*/
/*
function add() {
total = 0;
console.log(arguments);
for (var i = 0; i < arguments.length; i++) {
total += arguments[i];
}
return total;
}
var result = add(3, 6, 7);
console.log(result);
var result = add(1, 3, 5);
console.log(result);
*/
/*
function printHello() {
console.log('Hello');
}
printHello();
console.log(typeof printHello());
*/