...

/

Spin the Wheel Using Mathematical Formulas

Spin the Wheel Using Mathematical Formulas

Use mathematical formulas to spin the wheel at a random number of degrees and display the prize won by the user.

Introduction

Now that we’ve added the event listener and created an animation using tweens to rotate the wheel object by an angle of 1800 degrees, let's create an object to store all the prize information, and write a logic to randomly generate the number of degrees the wheel object rotates.

Create an object to store the prize details

We'll create an object that will consist of the following information related to the prizes shown in the wheel image:

  • The total number of prizes.

  • The name of each prize stored in an array.

Now let's look at the code below:

Press + to interact
// Define an object to store the prize details
let prizes_config = {
count: 12,
prize_names: ["3000 Credits", "35% Off", "Hard Luck", "70% OFF", "Swagpack", "100% OFF",
"Netflix Voucher", "50% Off", "Amazon Voucher", "8000 Credits", "T-shirt", "Coding Book"]
}

Explanation

  • Lines 2–8: We create a prizes_config object, which ...

Access this course and 1400+ top-rated courses and projects.