-
Notifications
You must be signed in to change notification settings - Fork 0
hpmework-16 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
olgakuzminagithub
wants to merge
1
commit into
master
Choose a base branch
from
homework_16
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
hpmework-16 #18
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Homework-16 Приложение</title> | ||
| <style> | ||
| li { | ||
| list-style: none; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
|
|
||
|
|
||
| <!--<script src="src/appTest.js"></script>--> | ||
| <script src="src/main.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* ТЕСТ */ | ||
|
|
||
| /* | ||
| * Добавьте реальных вопросов про JavaScript с вариантами | ||
| * ответов | ||
| * */ | ||
|
|
||
| // 3. При нажатии на кнопку если были выбраны правильные ответы, | ||
| // отображайте "ПРАВИЛЬНО" или не правильно | ||
| // или отображайте значек X или галочку, возле вопроса | ||
|
|
||
|
|
||
| const questions = [ | ||
| { | ||
| questionName: 'question 1', | ||
| answers: ['answer 1_1', 'answer 1_2', 'answer 1_3'], | ||
| correctAnswersIndexes: [1] | ||
| }, | ||
| { | ||
| questionName: 'question 2', | ||
| answers: ['answer 2_1', 'answer 2_2', 'answer 2_3'], | ||
| correctAnswersIndexes: [2] | ||
| }, | ||
| { | ||
| questionName: 'question 3', | ||
| answers: ['answer 3_1', 'answer 3_2', 'answer 3_3'], | ||
| correctAnswersIndexes: [1, 2] | ||
| } | ||
| ]; | ||
|
|
||
|
|
||
| const findCorrectAnswer = answerToValidate => { | ||
| let correctAnswers = questions.map(question => | ||
| question.correctAnswersIndexes.map(answerIndex => { | ||
| return question.answers[answerIndex]; | ||
| }) | ||
| ); | ||
|
|
||
| return correctAnswers.some(answer => { | ||
| return answer.includes(answerToValidate); | ||
| }); | ||
| }; | ||
|
|
||
| const app = { | ||
| questions, | ||
| testName: 'Тест по программированию', | ||
| buttonName: 'Проверить', | ||
| render() { | ||
| const main = this.newEl('main'); | ||
| const testName = this.newEl('h1'); | ||
| testName.textContent = this.testName; | ||
| const questionsList = this.newEl('ol'); | ||
| this.questions.forEach(question => { | ||
| const li = this.newEl('li'); | ||
| const questionHeader = this.newEl('h3'); | ||
| questionHeader.textContent = question.questionName; | ||
| const answers = this.newEl('ul'); | ||
| question.answers.forEach((answer, answerIndex) => { | ||
| answers.innerHTML += this.renderAnswer(answer, answerIndex); | ||
| }); | ||
|
|
||
| li.appendChild(questionHeader); | ||
| li.appendChild(answers); | ||
| questionsList.appendChild(li); | ||
| }); | ||
|
|
||
| main.appendChild(testName); | ||
| main.appendChild(questionsList); | ||
| document.body.appendChild(main); | ||
| const button = this.newEl('button'); | ||
| button.textContent = this.buttonName; | ||
| main.appendChild(button); | ||
| }, | ||
| renderAnswer(answer, answerIndex) { | ||
| const uniqId = `uniq_${Math.random()}_${answerIndex}`; | ||
| return ` | ||
| <li> | ||
| <input type="checkbox" id="${uniqId}"> | ||
| <label for="${uniqId}">${answer}</label> | ||
| </li> | ||
| ` | ||
| }, | ||
| newEl(elName) { | ||
| return document.createElement(elName); | ||
| } | ||
| }; | ||
|
|
||
| app.render(); | ||
|
|
||
|
|
||
|
|
||
| const newButton = document.createElement('button'); | ||
| newButton.textContent = 'Узнать ответы'; | ||
| document.body.appendChild(newButton); | ||
| newButton.onclick = function () { | ||
| const allAnswer = document.body.querySelectorAll('label'); | ||
| [...allAnswer].forEach( answer => { | ||
| const span = document.createElement('span'); | ||
| let yourAnswer = answer.textContent; | ||
| let labelStatus = findCorrectAnswer(yourAnswer) ? 'CORRECT' : 'INCORRECT'; | ||
| span.textContent = labelStatus; | ||
| answer.parentElement.insertBefore(span, answer); | ||
|
|
||
| }); | ||
| console.log(allAnswer); | ||
|
|
||
| }; | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| 0 Алгоритмы | ||
| Реализуйте функцию которая будет превращать трехмерный массив | ||
| в двухмерный, а если массив двухмерный, тогда в трехмерный массив | ||
| // solution([ [1, 'a'], [2, 'b'], [3, 'c'] ]) => [ [1, 2, 3], [a, b, c] ] | ||
| // solution([ [1, 3, 5], [2, 4, 6] ]) => [ [1, 2], [3, 4], [5, 6] ] | ||
| // solution([[]]) => [] | ||
| [ [ [ ] ] ] = [ [] ] | ||
| ИСПОЛЬЗУЙТЕ МЕТОДЫ МАССИВОВ ! | ||
| */ | ||
| // | ||
|
|
||
| /*yt получилось */ | ||
|
|
||
| const solution = arr => { | ||
| let newArr = []; | ||
|
|
||
| for ( let i = 0; i < arr.length; i++) { | ||
| let elem = arr[i]; | ||
| for (let j = 0; j < elem.length-1; j++) { | ||
| newArr[i] = elem[j]; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| solution([ [1, 'a'], [2, 'b'], [3, 'c'] ]); | ||
| solution([ [1, 3, 5], [2, 4, 6] ]); | ||
| solution([[]]); | ||
|
|
||
|
|
||
| const navigation = [ | ||
| {name: 'Главная'}, | ||
| { | ||
| name: 'Каталог', | ||
| children: [ | ||
| { | ||
| name: 'Компьютеры', | ||
| children: [ | ||
| { | ||
| name: 'Ноутбуки', | ||
| children: [{name: 'Apple'}, {name: 'HP'}] | ||
| }, | ||
| {name: 'Планшеты'} | ||
| ] | ||
| }, | ||
| { | ||
| name: 'Телевизоры', | ||
| children: [{name: '4k'}, {name: 'samrt-tv'}] | ||
| }, | ||
| ] | ||
| }, | ||
| {name: 'Профиль'} | ||
| ]; | ||
|
|
||
| /* | ||
| Визуализируйте массив, если в коллекции есть свойство | ||
| children, | ||
| тогда создайте вложенный лист | ||
| name - свойство h1 | ||
| children ul -> li | ||
| Используйте innerHTML | ||
| */ | ||
|
|
||
| /* | ||
| <h1>Main</h1> | ||
| <ul> | ||
| <h1>Catalog</h1> | ||
| <li> | ||
| <ul> | ||
| <h1>Comp</h1> | ||
| <ul> | ||
| <li> | ||
| <h1>Notebook</h1> | ||
| <h1>...</h1> | ||
| </li> | ||
| </ul> | ||
| </li> | ||
| */ | ||
|
|
||
| const visualArray = arr => { | ||
| return ` | ||
| ${arr.map(elem => { | ||
| if (elem.children) { | ||
| let arr = elem.children; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to not have naming collisions you could create it something like |
||
| return ` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please format code :) |
||
| <h1>${elem.name}</h1> | ||
| <li> | ||
| <ul> | ||
| ${visualArray(arr)} | ||
| </ul> | ||
| </li> | ||
| ` | ||
| } else { | ||
| return`<h1>${elem.name}</h1>` | ||
| } | ||
| }).join('')}` | ||
|
|
||
| }; | ||
|
|
||
| document.body.innerHTML += visualArray(navigation); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the
constkeyword instead oflet