Untitled
unknown
plain_text
a month ago
1.0 kB
1
Indexable
Never
onOptionClick(id: number) { const clickedIndex = this.currentOptions.findIndex((option) => option.id === id); if (clickedIndex !== -1) { const clickedOption = this.currentOptions[clickedIndex]; this.displayedOption = { name: clickedOption.name, image: clickedOption.image }; const availableOptions = this.allOptions.filter((option) => option.id !== clickedOption.id); if (availableOptions.length > 0) { const replacementOption = availableOptions[this.replacementIndex]; const otherIndex = clickedIndex === 0 ? 1 : 0; this.currentOptions[otherIndex] = replacementOption; this.replacementIndex++; console.log(this.currentOptions); // Check if is the end of the game and disable false if (this.allOptions.length === this.replacementIndex) { this.isDisabled = false; // Disable the unselected option const selectedOptionIndex = otherIndex === 0 ? 1 : 0; this.currentOptions[selectedOptionIndex].isDisabled = true; } } } }
Leave a Comment