• Welcome to SpeedSolving.com — the world’s largest puzzle community!

    You’re currently browsing as a guest, which means you have limited access to discussions, resources, member profiles, and community features.

    Join 50,000+ cubers and puzzle enthusiasts from around the world to ask questions, share solves, improve faster, and be part of the community.

    Registration is free, fast, and easy — create your account today.

    Already a member? Log in here to hide this message and start participating.

Need Help With Coding

Thanks Pat, worked wonderfully. I also finally changed it to make it reset to 0 after each time (derp) and add in the Time: x part. This made it look a little better. I tried to get it to start by clicking on the text first (setting focus) like yours, but then whenever I hit the start button (aka any key) it would reset to 0 and double up, not putting a time down. That's the next thing I want to conquer :)
 
Bump

Working on a different version of timer, and I have some problems (as expected), but I can't figure out how to solve them.

Why the avgX(x) function isn't working on my timer? I've been trying to change approaches, but I've gotten no where

How can I make it so that when I'm sorting the array, it will treat a DNF as the highest time (number)?

Note: I want to keep it so it's just JavaScript, so please try and keep it that way if you can.
 
I see at least 2 instances where "avgX()" is written "avgx()".

I just used the find function in notepad, and it came up in one place (the penalty function). It still wouldn't make sense why it isn't working otherwise, since I wasn't even testing it with the penalties. I've fixed it though, and it still doesn't work
 
You have "avg5()" in your code. Do you mean "avgX(5)"?

edit: Also, "total" is not defined in your avgX function.
 
Last edited:
You have "avg5()" in your code. Do you mean "avgX(5)"?

edit: Also, "total" is not defined in your avgX function.

It was originally meant to be just an avg5 function, but then I realized I could easily alter it so it would be avg of anything. I guess I forgot to change a couple things.

I've just defined total, but it still doesn't work :(
 
There are good developer tools for debugging in the Chrome web browser, including a Javascript Console. I'm not a Javascript programmer, but your code looks straightforward. You need a debugger if you're not using one.

You have at least 2 average functions, average() and avgX(). "total" is still not defined in one of them (if I'm seeing your current code).
 
The average function has total, and works perfectly. The avg function has total defined, but doesn't work. Are you viewing ztimer.tk's source? That is the most current version, and has it defined in both functions.

Also, how did you know I was using chrome?
 
I got it to take the first 5 solves, but for some reason it won't change to take the last 5 solves. I tried reverse() for the array, but that doesn't fix it.
 
Your avgX() function needs reworking. In the loop below, the variable "times" (originally an array) is set to a new value (and possibly no value) each iteration of the loop. Shift returns a value from an array, not an array.

for (i=0; times.length > x; i++){
var times = times.shift(); }

Also, I'm not sure you've set up your number sort function correctly. See this and set up the numerical sort method exactly as shown.

And there may be other problems in the function - I'm sure you'll figure it out.:D
 
Your avgX() function needs reworking. In the loop below, the variable "times" (originally an array) is set to a new value (and possibly no value) each iteration of the loop. Shift returns a value from an array, not an array.

for (i=0; times.length > x; i++){
var times = times.shift(); }

Also, I'm not sure you've set up your number sort function correctly. See this and set up the numerical sort method exactly as shown.

And there may be other problems in the function - I'm sure you'll figure it out.:D

Oops, I forgot that x.shift() only returns the number :p
The number function is set up just as it should be, it's just that the needed function is at the top of the code, and only on one line (so it's hard to find :p)

I just changed it, and the average itself still works great. It's just that it will not take the last 5, but rather the first 5 times.
 
I forget what I did to make it work (I did it during school), but it works now! I've also added in an avg12, 50, and 100, so that's great!

Now how do I make it so that when I sort the array, it treats DNF as the worst (highest) number?

Again, the URL is http://ztimer.tk/
 
Alright. Now that I have the avgX function fully working, I've been trying to debug other things, which are listed below.

When sorting numbers, DNF is not treated as the worst time.
The scramblers are not working (3-11 are custom made, Megaminx, Pyraminx, and Clock WCA, so I'm not sure why)

After I get these few things working, then I'll attempt to make it so you can add comments, as well as adding an inspection feature (with automatic +2s and DNFs). After I get that, then I'll officially release it!
 
Progress over the last day is amazing. Not only did I implement the inspection (with auto +2s/DNFs), I also had a very simple fix to sort the DNFs at the end. While doing that, the scramblers I've coded have magically fixed themselves (other than the ones that weren't working anyway, like the Mega and Pyra).

If you have any requests for things to implement into the timer, ask soon, as it'll be completely released after I get the scramblers working!
 
Does anybody know if, in Javascript, it's possible to use a variable when requesting another variable?

Example:
var cid = 1
var cname = cid(cid value)[1]

Is this possible, or am I SOL
 
Back
Top