Skip to content

Quiz settings#22

Merged
NataliaCichonska merged 6 commits intodevelopfrom
quiz-settings
Dec 8, 2021
Merged

Quiz settings#22
NataliaCichonska merged 6 commits intodevelopfrom
quiz-settings

Conversation

@NataliaCichonska
Copy link
Collaborator

Full view with validation is ready, settings shown in an alert.

@Nefariusek Nefariusek linked an issue Dec 6, 2021 that may be closed by this pull request
4 tasks
Copy link
Owner

@Nefariusek Nefariusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust according to the comments. Format code with prettier!

Comment on lines +17 to +25
button.addEventListener('click', () => {
if (what=="about"){
this.quizAbout=val;
}
if (what=="type"){
this.questionsType=val;
}

});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract handler to separate function to improve readability. Use strict equality.

}

});
return form;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract to separate function

const about = document.createElement('div');
const text = document.createElement('p');
text.innerText='Quiz about: '
about.append(text,this.createRadioButton("cats","about","about","left"), this.createRadioButton("dogs","about","about","right"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many arguments. Check the first comment.

questionsNum;
questionsType;

static createRadioButton(val,nameOfRadio,what,side){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many parameters. They are also so unintuitive.

val - replace with value;
nameOfRadio - I would change it to settingName;
what - what is "what" :P It can be removed. Pass event to the handler and use event.currentTarget.name to check which setting is clicked
side - currently, it is working fine, but this would be hard to add more buttons without rebuilding it

Comment on lines +53 to +57
const questionsNumberdiv = document.createElement('div');
const text = document.createElement('p');
text.innerText='Questions number: '
questionsNumberdiv.append(text, this.createQuestionsNumberInput());
return questionsNumberdiv;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questionsNumberdiv - be consistent, change to questionsNumberDiv

const questionsType = document.createElement('div');
const text = document.createElement('p');
text.innerText='Questions type: '
questionsType.append(text, this.createRadioButton("open","type","type","left"), this.createRadioButton("multiple choice","type","type","right"));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Comment on lines +25 to +36
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);
});
Copy link
Owner

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

() => {
            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);
        }

could've been extracted

Comment on lines +107 to +124
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,
);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above:
form.addEventListener('submit', (e) => this.validateForm(e));

and rest moved to this validate form function.

Copy link
Owner

@Nefariusek Nefariusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are areas for improvement. I left some comments. You can either fix it or merge it

@Nefariusek Nefariusek self-requested a review December 8, 2021 08:39
Copy link
Owner

@Nefariusek Nefariusek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are areas for improvement. I left some comments. You can either fix it or merge it

@NataliaCichonska NataliaCichonska merged commit 8701410 into develop Dec 8, 2021
@NataliaCichonska NataliaCichonska deleted the quiz-settings branch December 9, 2021 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI] Quiz Settings

2 participants