javascript - setTimeout() not working in return value -


i have add settimeout it's not working. want show question after 5 sec of end of sound.

self.getquestiontext = function() {      startsound('levelq', false);     settimeout(function() {     return self.questions[self.level() - 1].question;}, 5000);   } 

settimeout() in asynchronous , returns value in callback function. change structure of js.

instead of:

self.getquestiontext = function () {    startsound('levelq', false);     settimeout(function () {       return self.questions[self.level() - 1].question;     }, 5000);    }  // rest of code 

use callback structure:

self.getquestiontext = function () {      startsound('levelq', false);     settimeout(function () {         self.getquestiontext = self.questions[self.level() - 1].question;          // rest of code     }, 5000);  } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -