Skip to content

Commit ab8a9a9

Browse files
authored
Merge pull request #20 from EasyCode-JavaScriptReact-v1/homework_16
homework_16
2 parents e65dd72 + f3aa86b commit ab8a9a9

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>homework_16</title>
5+
<meta charset="utf-8" />
6+
<style type="text/css">
7+
li {
8+
list-style-type: none;
9+
}
10+
article {
11+
margin-left: 400px;
12+
}
13+
article > h1 {
14+
margin-left: 100px;
15+
}
16+
article > button {
17+
margin-left: 100px;
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
<script src="index.js"></script>
23+
</body>
24+
</html>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//Task1
2+
3+
const solution = arr => {
4+
return arr[0].map((_, index) => {
5+
return arr.map((value) => {
6+
return value[index];
7+
});
8+
});
9+
};
10+
11+
12+
console.log(solution([[1, 'a'], [2, 'b'], [3, 'c']]));
13+
console.log(solution([[1, 3, 5], [2, 4, 6]]));
14+
console.log(solution([[]]));
15+
16+
17+
18+
//Task2
19+
const navigation = [
20+
{
21+
name: 'Главная'
22+
},
23+
{
24+
name: 'Каталог',
25+
children: [
26+
{
27+
name: 'Компьютеры',
28+
children: [{name: 'Ноутбуки'}, {name: 'Планшеты'}]
29+
}
30+
]
31+
},
32+
{
33+
name: 'Профиль'
34+
}
35+
];
36+
37+
38+
// const visualArray = arr => {
39+
// let str = '';
40+
// arr.forEach(item => {
41+
// if(item.children) {
42+
// str += `<ul><h1>${item.name}</h1><li>`;
43+
// str += visualArray(item.children);
44+
// str += '</li></ul>';
45+
// } else {
46+
// str += `<h1>${item.name}</h1>`;
47+
// }
48+
// });
49+
// return str;
50+
// };
51+
// document.body.innerHTML = visualArray(navigation);
52+
53+
54+
55+
//Task3
56+
let app = {
57+
questions: [
58+
{
59+
textQuestions:'Какой оператор из этих - выполняет не только математические операции?',
60+
textAnswers: ['*', '-', '+', '/'],
61+
correctAnswer: 2
62+
},
63+
{
64+
textQuestions:'Какие конструкции для циклов есть в javascript?',
65+
textAnswers: ['Только две: for и while', 'Только одна: for', 'Три: for, while и do...while'],
66+
correctAnswer: 2
67+
},
68+
{
69+
textQuestions:'Что такое ECMAScript?',
70+
textAnswers: ['Спецификация языка Javascrip', 'Новый язык программирования', 'Переработанная реализация Javascript'],
71+
correctAnswer: 0
72+
}
73+
],
74+
createContainer() {
75+
let conteiner = document.createElement('article');
76+
conteiner.appendChild(this.createCaption());
77+
conteiner.appendChild(this.createQuestions());
78+
conteiner.appendChild(this.createButton());
79+
return conteiner;
80+
},
81+
createCaption() {
82+
let caption = document.createElement('h1');
83+
caption.textContent = 'Тест по програмированию';
84+
return caption;
85+
},
86+
createQuestions() {
87+
let id = 0;
88+
let list = document.createElement('ol');
89+
this.questions.forEach((questAnswer, qIndex) => {
90+
let question = document.createElement('li');
91+
question.textContent = questAnswer.textQuestions;
92+
let span = document.createElement('span');
93+
question.appendChild(span);
94+
let sectionAnswer = document.createElement('section');
95+
question.appendChild(sectionAnswer);
96+
97+
questAnswer.textAnswers.forEach((elem, aIndex) => {
98+
let idId = id++;
99+
let answer = document.createElement('p');
100+
let input = document.createElement('input');
101+
input.setAttribute('type', 'checkbox');
102+
input.setAttribute('id', `check${qIndex}-${aIndex}`);
103+
let label = document.createElement('label');
104+
label.setAttribute('for', `check${qIndex}-${aIndex}`);
105+
label.textContent = elem;
106+
answer.appendChild(input);
107+
answer.appendChild(label);
108+
109+
sectionAnswer.appendChild(answer);
110+
question.appendChild(sectionAnswer);
111+
list.appendChild(question);
112+
});
113+
114+
});
115+
return list;
116+
},
117+
createButton() {
118+
let button = document.createElement('button');
119+
button.textContent = 'Проверить мои результаты';
120+
return button;
121+
},
122+
render() {
123+
document.body.appendChild(this.createContainer());
124+
}
125+
};
126+
app.render();
127+
128+
let button = document.querySelector('button');
129+
button.onclick = function() {
130+
let questionsLi = document.querySelectorAll('li');
131+
[...questionsLi].forEach((elemLi, indexQuestion) =>{
132+
let possibleAnswer = elemLi.querySelectorAll('input');
133+
[...possibleAnswer].forEach((elem, index) => {
134+
if(elem.checked) {
135+
if(index === app.questions[indexQuestion].correctAnswer) {
136+
let appAnswer = elemLi.childNodes[1];
137+
appAnswer.setAttribute('style', 'color: #11f91d');
138+
appAnswer.textContent = ' Верно';
139+
140+
} else {
141+
let appAnswer = elemLi.childNodes[1];
142+
appAnswer.setAttribute('style', 'color: #f70408');
143+
appAnswer.textContent = ' Неверно';
144+
}
145+
}
146+
})
147+
})
148+
}

js-core/homeworks/homework-16/style.css

Whitespace-only changes.

0 commit comments

Comments
 (0)