Skip to content

Instantly share code, notes, and snippets.

@dicethedev
Created February 7, 2023 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dicethedev/4c46bffc4b0ffdc09a591dd356b37d20 to your computer and use it in GitHub Desktop.
Save dicethedev/4c46bffc4b0ffdc09a591dd356b37d20 to your computer and use it in GitHub Desktop.
<template>
<h1>Color Picker Game</h1>
<div>{{ message }}</div>
<button v-for="color in colors" :key="color" @click="matchColor(color)">
{{ color }}
</button>
</template>
<script>
import { ref, reactive } from "@vue/reactivity";
import colorPickerManager from "../composables/colorPickerGame-manager";
export default {
setup() {
// const colors = ["green", "red", "blue", "purple"];
// let message = ref("Pick a color...");
let { message } = colorPickerManager();
const { colors } = colorPickerManager();
const matchColor = (value) => {
// do a random color based on the array index;
const randomNumber = Math.floor(Math.random() * 3) + 1; //between 1 - 4
if (colors[randomNumber] === value) {
message.value = `You win... [answer: ${colors[randomNumber]}]`;
return;
}
message.value = `You loose [answer: ${colors[randomNumber]}]`;
};
return { colors, message, matchColor };
},
};
</script>
<style></style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment