Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
How to change a settimeout into a function instead of a string

Here are lines 38-41 of my code for a snake game on JS> I am using JsFiddle

createSnake();
locateApple();
setTimeout("gameCycle()", DELAY)

The setTimeout has the error: Implied eval consider passing a function instead of a string.

How should I go about fixing this?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Please Refer https://developer.mozilla.org/en-US/docs/Web/API/setTimeout

The setTimeout() accepts function or code as first parameter. Using code is not recommended. Use function like below,

function gameCycle() {}

setTimeout(gameCycle, 3000); // if your delay is 3s

// OR

setTimeout(function() {}, 3000);
about 4 years ago · Juan Pablo Isaza Report

0

You should use like this: setTimeout(gameCycle, DELAY)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!