r/learnprogramming • • Aug 04 '23

Unexpected function problem.

I have a small problem that I create a project in js, css, html, which is launched locally in the browser and when everything I did last worked normally, when I launched the script the next day, one function stopped working completely and the other one works incorrectly. When I ran the script (the current version) the next day, I did not modify these functions in any way, I did not change their calling context, nor did I change other functions that affect them in any way. The console in the code editor as well as in the Chrome browser does not have a single syntax error, etc. I always make copies of the entire script so that I can restore something if I messed up in the current version, or I would like to restore something as I did in the previous version. In these older copies, these functions worked normally, nothing happened, now if I remove this current version of the code and put the old one, where these functions should work, it's the same problem. Anyone know what could have happened? I haven't changed any settings in the browser either. In this case, it can't be a problem with the code, but with something from the outside.

1 Upvotes

15 comments sorted by

View all comments

1

u/lurgi Aug 04 '23

Could be a caching issue. It's possible that the code you were actually running yesterday is not the code you thought you were running.

My advice is to forget that it used to work and focus on what you have now (and use source code control, for Zod's sake). You have code that doesn't work. Debug it. I've been in the situation of "this used to work" quite a few times in my career and I can honestly say that trying to work out why it used to work has never been helpful. Memory is faulty and computers are weird. Focus on what you've got.

1

u/Tough_Pride4428 Aug 04 '23

Well, it's just that I built this function in a way that works. It's not a matter of I might have modified something or done something else that it doesn't work now. I care about this function because I don't see any other approaches to make it work like in this build.
It works all the time until some strange external factor comes along.
Also, debugging won't solve the problem at all, since the previous version of the entire application script was working all the time, and now it suddenly doesn't. That's a lot of logic says it can't be a script problem.

1

u/lurgi Aug 04 '23

It doesn't matter that the previous version worked. No one cares and you shouldn't either.

THIS VERSION DOESN'T.

I suggest you try to find out why.

0

u/Tough_Pride4428 Aug 05 '23

Well, it matters and it matters a lot, since the script is well written logically and syntactically and should work normally, but it doesn't work for some reason, it's very strange. I care because then something must have happened to the browser or something. If I don't solve this problem, I will have to say goodbye to my correct logic in the code for such a stupid reason and I will have to look for another solution.

1

u/lurgi Aug 05 '23

Oh, yes, well written and logical scripts are never the issue

Try using a different browser. Try reinstalling the browser. Try clearing the cache.

You could also try being a tiny bit more specific about the problem. All we know so far is that a function stopped working. I don't know what "stopped working" means (does it no longer get called? Does it do the wrong thing?) and you haven't provided any details about what should be happening and what is happening.

If you called your local mechanic and say your car isn't working, but you know it's not a problem with the car because the same car worked yesterday, they'd (a) laugh at you and (b) want to know what the problem is.

0

u/Tough_Pride4428 Aug 06 '23

Comparison with the car in relation to my situation makes no sense, but ok. You go to the mechanic with a problem with the car itself, not with something else that does not directly affect the car. In my case, the problem is something that directly affects the script. In addition, it "stopped working", as if it would not call at all. Returns no values. It is based on retrieving the current hour, minutes, etc. But it doesn't matter because others in the same context are called correctly.

1

u/lurgi Aug 06 '23

as if it would not call at all. Returns no values.

Which is it?

Is the function not called or is it called, but doesn't return a value?