# javascript Keypress code problem

**URL:** <https://forum.kirupa.com/t/javascript-keypress-code-problem/637420>\
**Category:** web dev\
**Created:** [November 10, 2017, 11:33pm UTC](https://forum.kirupa.com/t/javascript-keypress-code-problem/637420 "2017-11-10T23:33:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruth\_Harris\_Shumate](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ruth_harris_shumate/32/8785_2.png) [@Ruth\_Harris\_Shumate](https://forum.kirupa.com/u/Ruth_Harris_Shumate)\
**Post date:** [November 10, 2017, 11:33pm UTC](https://forum.kirupa.com/t/javascript-keypress-code-problem/637420/1 "2017-11-10T23:33:08Z")

</div>

I want to create a Javascript program that when I press a key it will give me a matching image. I have images named

Letter-ATumb, Letter-BThumb to Letter-ZThumb. Do I have to convert the code I get from keypress event to a letter character? Then I am lost especially if the solution is an array. Thanks for any input or thoughts out there. I may get this Javascript stuff eventually.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [November 11, 2017, 12:03am UTC](https://forum.kirupa.com/t/javascript-keypress-code-problem/637420/2 "2017-11-11T00:03:45Z")

</div>

> [@Ruth\_Harris\_Shumate](#):
>
> Do I have to convert the code I get from keypress event to a letter character?

Yup. If you’re using `charCode`, its not hard to do:

```
var letter = String.fromCharCode(event.charCode).toUpperCase();
var imageName = 'Letter-' + letter + 'Thumb';

```

---

<div class="post-metadata">

**Author:** ![Ruth\_Harris\_Shumate](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ruth_harris_shumate/32/8785_2.png) [@Ruth\_Harris\_Shumate](https://forum.kirupa.com/u/Ruth_Harris_Shumate)\
**Post date:** [November 11, 2017, 2:24am UTC](https://forum.kirupa.com/t/javascript-keypress-code-problem/637420/3 "2017-11-11T02:24:54Z")

</div>

That is all. I always think it is going to very hard! Thanks! I am going to have fun with this!
