-
Notifications
You must be signed in to change notification settings - Fork 1
Quiz settings #22
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
Quiz settings #22
Changes from 5 commits
d94c812
dd1be63
2adb62b
2518c34
ee6620d
c5a7197
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import './style.css'; | ||
| import './views/quiz-settings/quiz-settings.css'; | ||
| import {QuizSettings} from "./views/quiz-settings/quiz-settings"; | ||
|
|
||
| document.querySelector('#app').innerHTML = ` | ||
| <h1>CC first project</h1> | ||
| `; | ||
|
|
||
| document.querySelector('#app').appendChild(QuizSettings.showSettings()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| form { | ||
| width: 70%; | ||
| margin: auto; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-around; | ||
| align-items: center; | ||
| gap: 30px; | ||
| color: white; | ||
| } | ||
|
|
||
| form div { | ||
| width: 100%; | ||
| display: grid; | ||
| grid-template-columns: [first] 1fr [second] 1fr [third]; | ||
| align-items: center; | ||
| justify-items: center; | ||
| align-content: center; | ||
| gap: 5%; | ||
| } | ||
|
|
||
| input { | ||
| border: 0px; | ||
| border-radius: 7px; | ||
| width: 100%; | ||
| max-width: 450px; | ||
| background-color: #658080; | ||
| height: 50px; | ||
| display: inline-block; | ||
|
|
||
| } | ||
|
|
||
| .radioButton { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| input[type=radio] { | ||
| -webkit-appearance: none; | ||
| } | ||
|
|
||
| input[type=radio]:checked { | ||
| background-color: #191f24; | ||
| } | ||
|
|
||
| input[type=radio]:hover { | ||
| background-color: #3e505b; | ||
| } | ||
|
|
||
| input[type=submit]:active { | ||
| background-color: #263038; | ||
| } | ||
|
|
||
| form p { | ||
| grid-column-start: first; | ||
| grid-column-end: third; | ||
| } | ||
|
|
||
| #number { | ||
| width: 40%; | ||
| grid-column-start: first; | ||
| grid-column-end: third; | ||
| color: white; | ||
| text-align: center; | ||
| } | ||
|
|
||
| #number:hover { | ||
| background-color: #3e505b; | ||
| } | ||
|
|
||
| #submit { | ||
| width: 40%; | ||
| margin-top: 100px; | ||
| color: white; | ||
| } | ||
|
|
||
| #submit:hover { | ||
| width: 40%; | ||
| margin-top: 100px; | ||
| background-color: #1e272c; | ||
| } | ||
|
|
||
| label { | ||
| position: relative; | ||
| top: -35px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| class QuizSettings { | ||
| quizAbout; | ||
| questionsNum; | ||
| questionsType; | ||
|
|
||
| static createRadioButton(value, settingName) { | ||
| const div = document.createElement('div'); | ||
| div.setAttribute('class', 'radioButton') | ||
| const button = document.createElement('input'); | ||
| button.setAttribute('id', value); | ||
| button.type = 'radio'; | ||
| button.value = value; | ||
| button.name = settingName; | ||
| const label = document.createElement('label'); | ||
| label.setAttribute('for', value); | ||
| label.innerText = value; | ||
| this.addEventListenerToComponent(button, 'click', settingName, value); | ||
| div.append(button, label); | ||
| return div; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static addEventListenerToComponent(component, event, settingName, value) { | ||
| component.addEventListener(event, () => { | ||
| if (settingName === 'quizAbout') { | ||
| this.quizAbout = value; | ||
| } | ||
| if (settingName === 'questionsType') { | ||
| this.questionsType = value; | ||
| } | ||
| if (settingName === 'questionsNum') { | ||
| this.questionsNum = component.value; | ||
| } | ||
| console.log(this.quizAbout, this.questionsType, this.questionsNum); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static createAboutSection() { | ||
| const about = document.createElement('div'); | ||
| const text = document.createElement('p'); | ||
| text.innerText = 'Quiz about: '; | ||
| about.append( | ||
| text, | ||
| this.createRadioButton('cats', 'quizAbout'), | ||
| this.createRadioButton('dogs', 'quizAbout'), | ||
| ); | ||
| return about; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static createQuestionsNumberInput() { | ||
| const questionsNumber = document.createElement('input'); | ||
| questionsNumber.setAttribute('id', 'number'); | ||
| this.addEventListenerToComponent(questionsNumber, 'input', 'questionsNum', questionsNumber) | ||
| return questionsNumber; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static createQuestionsNumberdiv() { | ||
| const questionsNumberdiv = document.createElement('div'); | ||
| const text = document.createElement('p'); | ||
| text.innerText = 'Questions number: '; | ||
| questionsNumberdiv.append(text, this.createQuestionsNumberInput()); | ||
| return questionsNumberdiv; | ||
|
Comment on lines
+53
to
+69
Owner
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. questionsNumberdiv - be consistent, change to questionsNumberDiv |
||
| } | ||
|
|
||
|
|
||
|
|
||
| static createQuestionsTypeSection() { | ||
| const questionsType = document.createElement('div'); | ||
| const text = document.createElement('p'); | ||
| text.innerText = 'Questions type: '; | ||
| questionsType.append( | ||
| text, | ||
| this.createRadioButton('open', 'questionsType'), | ||
| this.createRadioButton('multiple choice', 'questionsType'), | ||
| ); | ||
| return questionsType; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static createButtonStartQuiz() { | ||
| const buttonStartQuiz = document.createElement('input'); | ||
| buttonStartQuiz.type = 'submit'; | ||
| buttonStartQuiz.setAttribute('id', 'submit'); | ||
| buttonStartQuiz.value = 'Start Quiz'; | ||
| return buttonStartQuiz; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| static createForm() { | ||
| const form = document.createElement('form'); | ||
|
|
||
| form.append( | ||
| this.createAboutSection(), | ||
| this.createQuestionsNumberdiv(), | ||
| this.createQuestionsTypeSection(), | ||
| this.createButtonStartQuiz() | ||
| ); | ||
| form.addEventListener('submit', (e) => { | ||
| e.preventDefault(); | ||
| if (this.questionsNum === undefined || this.questionsNum < 1 || this.questionsNum > 20) { | ||
| alert('Insert questions number between 1 and 20'); | ||
| } else if (this.quizAbout === undefined) { | ||
| alert('Choose animals'); | ||
| } else if (this.quizAbout === undefined) { | ||
| alert('Choose questionsType'); | ||
| } else { | ||
| alert( | ||
| 'Quiz about: ' + | ||
| this.quizAbout + | ||
| '\nQuestions number: ' + | ||
| this.questionsNum + | ||
| '\nQuestions type: ' + | ||
| this.questionsType, | ||
| ); | ||
| } | ||
|
Comment on lines
+107
to
+124
Owner
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. Same as above: and rest moved to this validate form function. |
||
| }); | ||
| return form; | ||
|
Owner
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. Extract to separate function |
||
| } | ||
|
|
||
|
|
||
|
|
||
| static showSettings() { | ||
| const settings = document.createElement('div'); | ||
| settings.appendChild(this.createForm()); | ||
| settings.setAttribute('id', 'quiz-settings'); | ||
|
|
||
| return settings; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| export { | ||
| QuizSettings | ||
| }; | ||
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.
Keep in mind, that
we can pass a function to the addEventListener, so
could've been extracted