# Score in game causes error code

**URL:** <https://forum.code.org/t/score-in-game-causes-error-code/31763>\
**Category:** Coding and Debugging Help\
**Tags:** csd-unit-3-lesson-17\
**Created:** [November 21, 2019, 4:35pm UTC](https://forum.code.org/t/score-in-game-causes-error-code/31763 "2019-11-21T16:35:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lkeil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lkeil/32/5239_2.png) [@lkeil](https://forum.code.org/u/lkeil)\
**Post date:** [November 21, 2019, 4:35pm UTC](https://forum.code.org/t/score-in-game-causes-error-code/31763/1 "2019-11-21T16:35:54Z")

</div>

Score in game causes error code, even though same code for score works in previous level/lessons

**Link to the project or level:** [https://studio.code.org/projects/gamelab/xJdz4IZggqtm0Zu9wFoYHftMhulWZhNw8upHZa63I9s](https://studio.code.org/projects/gamelab/xJdz4IZggqtm0Zu9wFoYHftMhulWZhNw8upHZa63I9s)  
**What I expect to happen:** score shows during game play  
_What actually happens:_\* ERROR: Line: 12: TypeError: Cannot read property ‘toString’ of undefined  
**What I’ve (& two other students) tried:** copy/paste code from working score game, build code again, switching browsers, logoff/login

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [November 21, 2019, 5:30pm UTC](https://forum.code.org/t/score-in-game-causes-error-code/31763/2 "2019-11-21T17:30:50Z")

</div>

Lines 5 & 39 both try to declare the variable “score”. Try removing the var block from line 39 and only having it say “score=score+1” (without the “var”).

That should fix the error!

Best of luck!

Mike

---

<div class="post-metadata">

**Author:** ![kookooloopdaking](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/kookooloopdaking/32/5224_2.png) [@kookooloopdaking](https://forum.code.org/u/kookooloopdaking)\
**Post date:** [November 22, 2019, 4:35pm UTC](https://forum.code.org/t/score-in-game-causes-error-code/31763/3 "2019-11-22T16:35:56Z")

</div>

Line 39: score is already defined

You don’t want to define a variable twice, because the code won’t know which variable to use, thus the error. if you remove the var on line 39, it should work.

---

<div class="post-metadata">

**Author:** ![lkeil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lkeil/32/5239_2.png) [@lkeil](https://forum.code.org/u/lkeil)\
**Post date:** [December 11, 2019, 6:11pm UTC](https://forum.code.org/t/score-in-game-causes-error-code/31763/4 "2019-12-11T18:11:16Z")

</div>

The students were able to correct the errors and successfully get the program to work.  
Thank you for the help!  
I GREATLY appreciate your help!! 😃
