# sim error failed code undefined

**URL:** https://forum.makecode.com/t/sim-error-failed-code-undefined/27901
**Category:** Help
**Created:** [March 23, 2024, 12:13am UTC](https://forum.makecode.com/t/sim-error-failed-code-undefined/27901 "2024-03-23T00:13:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![23binbo](https://avatars.discourse-cdn.com/v4/letter/2/d26b3c/32.png) [@23binbo](https://forum.makecode.com/u/23binbo)
#### Post date: [March 23, 2024, 12:13am UTC](https://forum.makecode.com/t/sim-error-failed-code-undefined/27901/1 "2024-03-23T00:13:28Z")

</div>

I keep getting failed cast undefined for the code below im not sure why

> **[experiment1](https://makecode.microbit.org/38328-19627-16925-60401)**
>
> Made with ❤️ in Microsoft MakeCode for micro:bit.

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [March 23, 2024, 12:53am UTC](https://forum.makecode.com/t/sim-error-failed-code-undefined/27901/2 "2024-03-23T00:53:06Z")

</div>

Welcome, @23binbo !

MakeCode is unhappy with this block:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c293a0dca389b9a8dbd38752bd2a70e4b93203cf.png)

If the length of the array is zero, then it contains no items. If it contains no items, then you cannot get the value at index 0—it does not exist.
