# Event-Driven Programming Lesson 7

**URL:** https://forum.code.org/t/event-driven-programming-lesson-7/38775
**Category:** Unit and Lesson Discussion
**Created:** [December 7, 2023, 11:36am UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775 "2023-12-07T11:36:32Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![olopez](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@olopez](https://forum.code.org/u/olopez)
#### Post date: [December 7, 2023, 11:36am UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/1 "2023-12-07T11:36:33Z")

</div>

I am working on lesson 7 of event-driven programming and wonder why I cannot declare my variables outside an onEvent block. I am working to create a Madlib and have to get user input and then write it out with the user’s responses, but I have to do all that inside of the onEvent block instead of just creating a variable to save the user’s input, then use that input with onEvent command to write out the information.

---

<div class="post-metadata">

### Author: ![mriley](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@mriley](https://forum.code.org/u/mriley)
#### Post date: [December 7, 2023, 7:35pm UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/2 "2023-12-07T19:35:14Z")

</div>

Can you add a link to the project?

---

<div class="post-metadata">

### Author: ![sylvia.wood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/sylvia.wood/32/5622_2.png) [@sylvia.wood](https://forum.code.org/u/sylvia.wood)
#### Post date: [December 8, 2023, 11:53am UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/3 "2023-12-08T11:53:29Z")

</div>

@olopez Oscar thank you for posting to the forum. As @mriley requested, a copy or link of your code would give us a better understanding of your question.  
We are happy to help.  
Sylvia

---

<div class="post-metadata">

### Author: ![olopez](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@olopez](https://forum.code.org/u/olopez)
#### Post date: [December 8, 2023, 1:14pm UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/4 "2023-12-08T13:14:25Z")

</div>

[Event driven Programming Lesson 7-11](https://studio.code.org/projects/applab/PiuFnr833jAImmDZMTa0kZGV4BrbtQEPf8LrBQCxEHk)  
Above is a copy of the program in question. Thank you in advance for your feedback

---

<div class="post-metadata">

### Author: ![lindsay.davis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/lindsay.davis/32/7632_2.png) [@lindsay.davis](https://forum.code.org/u/lindsay.davis)
#### Post date: [December 11, 2023, 4:00pm UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/5 "2023-12-11T16:00:34Z")

</div>

Hi Oscar,  
Thanks for sharing the link to your project 🙂  
I [remixed your project](https://studio.code.org/projects/applab/ki1bsEZl3e7fznj0Sxowowck-JloPQg71LbtjzNcOso), and declared each variable above the on Event block, and then removed the “var” from each variable’s assignment inside of the on Event. When I run the app, it seems to work, the input I type is shown in the message.

One issue I sometimes come across with my students that might be related to what wasn’t working for you is if they have var in both spots-- above the onEvent and inside of the onEvent for the same variable.  
This creates troubles, as a variable should only be declared with “var” one time in the code. Once the declaration has been done once, the “baggie” has been created and you can return to it and store new values in it without typing var again.

Does this help get your project working?

Best,  
Lindsay

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/0/04dfab32f103c2dfbaf66e092df912a9f52d9d6d.png)

---

<div class="post-metadata">

### Author: ![olopez](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@olopez](https://forum.code.org/u/olopez)
#### Post date: [December 14, 2023, 10:46pm UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/6 "2023-12-14T22:46:06Z")

</div>

Thank you you for your reponse and solution, that is very helpful.

---

<div class="post-metadata">

### Author: ![sylvia.wood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/sylvia.wood/32/5622_2.png) [@sylvia.wood](https://forum.code.org/u/sylvia.wood)
#### Post date: [December 25, 2023, 1:12pm UTC](https://forum.code.org/t/event-driven-programming-lesson-7/38775/7 "2023-12-25T13:12:06Z")

</div>

Thanks @lindsay.davis for a great explanation.
