Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simplify User Steps to Single Digits

ANSWERED

On one of my clock faces, I would like to simplify the amount steps a user has. Basically, if the user has 0-1,000 steps, it will display a 0, if the user has 1,000-2,000 steps, it will display a 1, if the user has 2,000-3,000 steps, it will display a 2, and so on and so forth. If the user has over 10,000 steps, it will just display a 10. I know that I will need if-then statements, but I am not sure how to do so. Any suggestions?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

You could indeed use if-then, but I wouldn't. I'd mess around with something like

Math.floor(steps/1000)
Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
6 REPLIES 6

You could indeed use if-then, but I wouldn't. I'd mess around with something like

Math.floor(steps/1000)
Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you so much. Your solution seems to make sense. However, that would give me a decimal number. Is there a way to not include the numbers after the decimal point? I know there is an option to set the <text-length> but according to the Fitbit guides, the number will always be rounded to a multiple of 4. If you know a way, would you mind giving me the code fully written out? I am not a great programmer, so I am not quite sure what to do.

Best Answer
0 Votes
Best Answer
0 Votes

Thank you so much. I read through the reference page, and it was very helpful. I figured out how to set the text length to not include the numbers after the decimal point. It was quite simple, actually.

Best Answer

For those curious, here is the code I used:

 

let steps = (today.adjusted.steps || 0);
const lvlsteps = document.getElementById("lvlsteps");
lvlsteps.text = `Level: ${Math.floor(steps/1000)}`;

 

Best Answer

Nice; well done!

Peter McLennan
Gondwana Software
Best Answer
0 Votes