Skip to content

Commit 36b0974

Browse files
homework_4
1 parent d356d36 commit 36b0974

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Home work 4</title>
6+
</head>
7+
<body>
8+
9+
<script src="src/main.js"></script>
10+
</body>
11+
</html>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//Task1
2+
function testValue (value) {
3+
if (typeof value == 'number' || typeof value == 'object') {
4+
return true;
5+
};
6+
if (typeof value == 'function') {
7+
return false;
8+
};
9+
if (typeof value == 'string' && value.length != 10) {
10+
return `Длина вашей строки: ${value.length}.`;
11+
};
12+
if (typeof value == 'string' && value.length == 10) {
13+
return 'you win';
14+
}
15+
}
16+
let typeofNumber = 10;
17+
let typeofObject = {
18+
name: 'Natalia'
19+
};
20+
let typeofFunction = function () {
21+
return 2 + 2;
22+
};
23+
let typeofString = 'JS';
24+
let typeofString10 = 'javascript';
25+
26+
console.log(testValue(typeofNumber));//true
27+
console.log(testValue(typeofObject));//true
28+
console.log(testValue(typeofFunction));//false
29+
console.log(testValue(typeofString));//'длина вашей строки: <длина строки>'
30+
console.log(testValue(typeofString10));//'you win'
31+
32+
33+
34+
//Task2
35+
function numbersBetween(a, b) {
36+
if (typeof a == 'number' && typeof b == 'number') {
37+
for (let i = a; i <= b; i++) {
38+
console.log(i);
39+
};
40+
};
41+
};
42+
43+
numbersBetween(3, 5);
44+
45+
numbersBetween(10, 12);
46+
47+
48+
49+
//Task3
50+
function FizzBuzz(num) {
51+
if (num % 3 == 0 && num % 5 == 0) {
52+
console.log('FizzBuzz');
53+
} else if (num % 3 == 0) {
54+
console.log('Fizz');
55+
} else if (num % 5 == 0) {
56+
console.log('Buzz');
57+
} else {
58+
console.log(num);
59+
};
60+
}
61+
62+
function fizzBuzz100(number) {
63+
for (let i = number; i <= 100; i++) {
64+
FizzBuzz(i);
65+
};
66+
};
67+
68+
fizzBuzz100(80);
69+
70+
71+
72+
//Task4
73+
let arr = [1, null, undefined, 'str', {}, [], function() {}];
74+
let array = `Массив – разновидность объекта.`;
75+
let typeofNull = 'null – это не объект, а отдельный тип данных';
76+
77+
function typesVariablesInArray (arg) {
78+
let newArr = [];
79+
for (let i = 0; i < arr.length; i++) {
80+
let type = typeof arr[i];
81+
if (Array.isArray(arr[i])) {
82+
newArr[i] = `${type}; ${array}`
83+
} else if (arr[i] === null){
84+
newArr[i] = `${type}; ${typeofNull}`
85+
} else {
86+
newArr[i] = type;
87+
}
88+
};
89+
return newArr;
90+
};
91+
92+
console.log(typesVariablesInArray(arr));
93+
94+
95+
96+
//@@SUPER@@
97+
98+
let array2 = Array.from({length: 35},
99+
(value, index) => (index % 2 ? {age: index + 2} : {age: NaN}),
100+
);
101+
102+
function solution(arr) {
103+
for (let i = 0; i < arr.length; i++) {
104+
let obj = arr[i];
105+
if (isNaN(obj.age)) {
106+
obj.unknownAge = true;
107+
};
108+
};
109+
};
110+
111+
solution(array2);
112+
113+
function solution2 (arr2) {
114+
let secondNewArr = [];
115+
let obj;
116+
for (let i = 0; i < arr2.length; i++) {
117+
obj = arr2[i];
118+
if ('unknownAge' in obj) {
119+
secondNewArr[secondNewArr.length] = obj;
120+
};
121+
};
122+
return secondNewArr;
123+
}
124+
125+
console.log(solution2(array2));
126+
127+
128+
129+
// Classwork problem task
130+
let webStore = {
131+
category: {
132+
noteBook: ['Asus', 'Lenovo', 'Dell', 'HP'],
133+
mobile: ['Nokia', 'Apple', 'Sony']
134+
}
135+
};
136+
137+
let category = webStore.category;
138+
139+
function dataProcessing (data) {
140+
for (let key in category){
141+
console.log(`Категория: ${key}`);
142+
for (let i = 0; i < category[key].length; i++){
143+
console.log(` Содержимое категории: ${category[key][i]}`);
144+
};
145+
};
146+
};
147+
dataProcessing(webStore);

0 commit comments

Comments
 (0)