P5.js code for creating a calculator tip app confused

sorry I had to copy the url from your screenshot to try the code. when I run the “production” link, I get error at image(img, 0, 0), which I guess, it’s because until pickEvent is fired, img remains empty so that it cannot draw anything.

by the way it’s a bit weird that repl.it shows “script error” message. I wonder if theres a way to show proper error message…