0

I want to increase my minutes var everytime the seconds var reaches '00' in javascript.

So for instance Don't increase it when it is 82,761,912 But when it is 82,762,000

How can I check for this? I tried:

if(Math.floor(seconds) == seconds)

and

If(seconds % 1 != 0)

But neither of them produced the correct results.

Chud37
  • 4,907
  • 13
  • 64
  • 116

4 Answers4

1

You can simply use test

  /0{2}$/
  • 0{2} - Match 0 two time
  • $ - End of string

let testZeros = (str) => /0{2}$/.test(str)

console.log(testZeros(12345))
console.log(testZeros(123450))
console.log(testZeros(1234500))

Or you can do

let testZeros = (num) => num % 100 === 0

console.log(testZeros(12345))
console.log(testZeros(123450))
console.log(testZeros(1234500))

We have endsWith also

let testZeros = (str) => (str +'').endsWith('00')

console.log(testZeros(12345))
console.log(testZeros(123450))
console.log(testZeros(1234500))
Code Maniac
  • 37,143
  • 5
  • 39
  • 60
0

From what you describe, you're looking for a modulo 100 operation, but since you're dealing with seconds and minutes, you actually need a modulo 60 operation:

const test = (seconds) => !(seconds % 60);

console.log(test(82761912)); // false
console.log(test(82762020)); // true
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
0

Your second option should work with some tweaking. Say,


    if(seconds % 100 == 0){
    //increment minutes here
    }

Etin
  • 365
  • 1
  • 9
0

You can try this

if(seconds % 100 == 0)
 alert("end with 00");
else
 alert("Not end with 00");
Praveen
  • 240
  • 1
  • 5