-2

I have a Little js "module" with an interval function which should Output a console log every second, but it just puts it out once what am I missing in this logic?

const calc = {

    render () {
        this.foo;
    },

    foo() {
        setTimeout(() => {
            console.log("test");
        }, 1000);
    },
}

calc.render();
tigerel
  • 317
  • 2
  • 7
  • 15

1 Answers1

2

You should use setInterval instead of setTimeout if you want a function to be called repeatedly:

const calc = {
  render() {
    this.foo();
  },

  foo() {
    setInterval(() => {
      console.log("test");
    }, 1000);
  },
}

calc.render();
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
Shishir Arora
  • 5,521
  • 4
  • 30
  • 35