mirror of
https://github.com/jlengrand/polymer-summit-whose-flag-polymer-3.git
synced 2026-03-10 08:41:17 +00:00
Add components private methods
This commit is contained in:
@@ -98,6 +98,37 @@ export class WhoseFlagApp extends Element {
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
_selectAnswer(event) {
|
||||
let clickedButton = event.target;
|
||||
this.userAnswer = clickedButton.textContent;
|
||||
if (this.userAnswer == this.correctAnswer.name) {
|
||||
this.outputMessage = `${this.userAnswer} is correct!`;
|
||||
}
|
||||
else {
|
||||
this.outputMessage = `Nope! The correct answer is ${this.correctAnswer.name} !`;
|
||||
}
|
||||
}
|
||||
|
||||
_handleResponse(event) {
|
||||
this.countryList = event.detail.response.countrycodes;
|
||||
while (!this.countryA || !this.countryB || (this.countryA.code == this.countryB.code)){
|
||||
this.countryA = this.countryList[this.__getRandomCountry()];
|
||||
this.countryB = this.countryList[this.__getRandomCountry()];
|
||||
}
|
||||
this.correctAnswer = this.countryA;
|
||||
|
||||
let coin = (Math.floor(Math.random() * 2));
|
||||
this.correctAnswer = coin == 1 ? this.countryA : this.countryB;
|
||||
}
|
||||
|
||||
__getRandomCountry() {
|
||||
return Math.floor(Math.random() * (this.countryList.length));
|
||||
}
|
||||
|
||||
_restart() {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('whose-flag-app', WhoseFlagApp);
|
||||
Reference in New Issue
Block a user