1

I am working on a webpage that responds to a question with a random answer from a IDB store. There are currently 8 answers in the store, but I am planning on giving the user the option to add more. In order to determine the answer to respond with, I first want to be able to find the number of answers in the store.

var count = store.count()  
var aCount = 0;

count.onsuccess=function() {  
    aCount = count.result;  
    console.log(aCount);  
}  

console.log(aCount);  

Output:
0
8

For some reason the console.log outside of the success handler only outputs 0. Any ideas on how to fix this would greatly appreciated.

Hanzai
  • 11
  • 1
  • You will need to learn about how to write asynchronous JavaScript. See https://stackoverflow.com/questions/14220321 – Josh Nov 25 '20 at 15:04

0 Answers0