white or black

By alexdmotoc · Web · Vue 3.5.45 · Published 22 November 2026

0 likes Watch how it was written Remix Report

Code

<script setup>
  import { ref } from "vue";
  
  const angle = ref(0);
  const top = ref("white");
  const bet = ref(null);
  const wins = ref(0);

  function spin(color) {
    bet.value = color;
    const result = Math.random() < 0.5 ? "white" : "black";
    angle.value += 1800 + (result === top.value ? 0 : 180);
    top.value = result;
  }

  function landed() {
    if (bet.value === top.value) wins.value++;
    bet.value = null;
  }
</script>

<template>
  <div class="page">
    <div>V</div>
    <div class="coin" :style="{ rotate: angle + 'deg' }" @transitionend="landed"/>
  </div>
  <div>
    <button :disabled="bet" @click="spin('white')">White</button>
    <button :disabled="bet" @click="spin('black')">Black</button>
  </div>
  <p>Wins: {{ wins }}</p>
</template>

  <style>
    .page {
      height: 70vh;
      display: grid;
      place-content: center;
      justify-items: center;
      gap: 12px;
    }

    .coin {
      width: 200px;
      height: 200px;
      border: 3px solid black;
      border-radius: 50%;
      background: linear-gradient(white 50%, black 50%);
      transition: rotate 3s ease-out;
    }
  </style>

© 2026 alexdmotoc. Published under the MIT licence: you may copy and change this code if you keep this credit.

Comments (0)

No comments yet.

Sign in to like or comment.