L
L
LordeckiyDavid2020-11-28 18:46:04
typescript
LordeckiyDavid, 2020-11-28 18:46:04

How to remove assignment error?

Hello everyone, the mistake is stupid, but I don’t understand how to fix it (I’m new to JS, from the word at all.).
There is an error in the line "out[i].innerHTML = n;
I wrote in TypeScript, it complains about this line, namely "Type 'number' is not assignable to type 'string'". I will
attach the TypeScript code

const time: number = 1000;
const step: number = 10;
function preloader(num: number[]) {
    let out = document.querySelectorAll('h1.head-p-card');
    let n = 0;
    for (let i = 0; i < 3; i++) {
        let interval = setInterval(() => {
            n = n + step;
            if (n == num[i]) {
                clearInterval(interval);
            }
            out[i].innerHTML = n;
        });
    }
}
preloader([500, 500, 500]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-11-28
@Kozack

Like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question