+ 2

play audio only once in html page

This question maybe out of scope in sololearn but, i have received numerous helps here in sololearn so, i just want to ask here in hopes of getting some answers so please dont mind. So, what i am doing is I have a table 9x10 matrix numbered from 1 to 90. I am randomly picking a random each 5 seconds and gives that random number to the javascript. What i want to do is i want to update the cell color of the table that contains the random number and play and audio of the chosen number. I am able to change the cells color but my audio plays more then a thousand time in one second so it gives an effect like an echo so how can i solve this. ? The problem is that the javascript function that checks the random number in the table is called non stop so even if i set a variable 'count' to set it to 1 when the audio plays for the first time and put a condition to skip playing the audio if the condition doesn't apply, it doesnt work because the method or the function that check and plays the audio gets called everytime and the variable count is set back to its initial initialised number. Can i use cookies or session to store the number thats being randomly picked and use that to validate and play the audio only once ? Here is the link to the javascript and the table https://code.sololearn.com/WW55HmueD8al

9th Jun 2022, 7:55 PM
Akang Toshi
Akang Toshi - avatar
5 Réponses
+ 3
getData() should do just one thing, get data. There should be a separate function to check table every five seconds
9th Jun 2022, 10:12 PM
ODLNT
ODLNT - avatar
+ 2
Thanks EVERYONE i have solved it by using sessionStorage. Also, i have updated the changes in the code so you can check the comments there if you are curious :) https://code.sololearn.com/WW55HmueD8al
10th Jun 2022, 9:16 AM
Akang Toshi
Akang Toshi - avatar
0
Umm.. Chris Coder i dont think it will work because the function getData() itself is being called non stop so even if we loop out by using a break or continue , right after it loops out from the function the same getData() function gets called again ..continuously. i am making a real time updates so it creates some issue . But , anyway thanks for your suggestion I'll try that
9th Jun 2022, 8:10 PM
Akang Toshi
Akang Toshi - avatar
0
Yes delay is there random number is being picked every 5 seconds. 🙂
9th Jun 2022, 8:34 PM
Akang Toshi
Akang Toshi - avatar
0
The problem is within that 5 sec duration the function getData () is called numerous times. Not only once .
9th Jun 2022, 8:42 PM
Akang Toshi
Akang Toshi - avatar