DEV Community

Discussion on: Feedback on my JavaScript project

Collapse
 
ptifur profile image
Y

Hi! If there is room for one more question, here is where I'm stuck with this app 🙊

I started working in a single file. Then made attempt to break it into modules. And when I move those plus and minus event listeners to a separate file, I can't properly pass the NEW_LETTERS value back to the main app.

Created new branch to illustrate it github.com/ptifur/javascript-pract...

Perhaps you could guide me in the right direction 🤓

Thread Thread
 
alexanderjanke profile image
Alex Janke

Easiest would be to write a function setNewLetters (choose whatever name) in your script.js that sets the value for you.

// in script.js
export function setNewLetters(newValue) {
  if (!newValue) return;
  newLetters = newValue;
} 

So you can then call this function in your event listeners and update your variable this way. Skips passing values back and forth, back and forth.

Thread Thread
 
ptifur profile image
Y

Thanks for the insight!

Didn't know you can call the functions both ways. Guess this will save me some time stumbling through tutorials 😜