Problem with setInterval to change number

  Kiến thức lập trình

I have a problem with following Code:

"use strict";

//Get Elements with Classes
let clock_hours_big = document.getElementsByClassName("clock__hours-big")[0];
let clock_hours_low = document.getElementsByClassName("clock__hours-low")[0];
let clock_seconds_big = document.getElementsByClassName("clock__seconds-big")[0];
let clock_seconds_low = document.getElementsByClassName("clock__seconds-low")[0];

//create Variables
let firstNumber = 0;
let secondNumber = 0;
let thirdNumber = 0;
let fourthNumber = 0;
let headline = "h1";

//change time of clock in function
let showNumbers = function(selectQuery, selectPosition, selectNumber) {
    let Position = selectPosition.querySelector(selectQuery);
    Position.textContent = parseInt(selectNumber);
}
let changeNumbers = function() {
    setInterval(function() {
        firstNumber = firstNumber + 1;
    },1000)
}

showNumbers(headline,clock_hours_big, firstNumber);
showNumbers(headline,clock_hours_low, secondNumber);
showNumbers(headline,clock_seconds_big, thirdNumber);
showNumbers(headline,clock_seconds_low, fourthNumber);
changeNumbers();

i like to develop a timer, but my function “changeNumbers()” dont work and i dont know why. In this function i like to change the number of the variable “firstNumber” and then i like to show it in other function, which is called “showNumbers”. Does anyone have a solution for this problem?

LEAVE A COMMENT