# Magic 8 Ball : Frontend Coding Exercise

**URL:** <https://forum.kirupa.com/t/magic-8-ball-frontend-coding-exercise/683594>\
**Category:** programming\
**Created:** [October 6, 2026, 8:31pm UTC](https://forum.kirupa.com/t/magic-8-ball-frontend-coding-exercise/683594 "2026-10-06T20:31:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [October 6, 2026, 8:31pm UTC](https://forum.kirupa.com/t/magic-8-ball-frontend-coding-exercise/683594/1 "2026-10-06T20:31:54Z")

</div>

This is where you can share your code for solving the [Magic 8 Ball](https://www.kirupa.com/codingexercises/magic_8_ball.htm) exercise 🙂

---

<div class="post-metadata">

**Author:** ![WaffleFries](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wafflefries/32/31185_2.png) [@WaffleFries](https://forum.kirupa.com/u/WaffleFries)\
**Post date:** [October 6, 2026, 9:20pm UTC](https://forum.kirupa.com/t/magic-8-ball-frontend-coding-exercise/683594/2 "2026-10-06T21:20:17Z")

</div>

This is a fun one. I’m curious how many people are going with a simple array and `Math.random()` versus something fancier like a weighted list of responses. For the basic version, it’s just a quick:

```auto
const responses = ["Yes", "No", "Maybe"];
const randomIndex = Math.floor(Math.random() * responses.length);
const answer = responses[randomIndex];

```

I’m lowkey tempted to try a version where “outlook good” shows up more often than "don’t count on it. " Maybe next time!
