I want to play audio as an alert but I'm getting an error like "Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
HTML Code:
<audio id="alarm" src="alarm.mp3"></audio>
JavaScript Code:
function alarm() {
var value = document.getElementById("rvoltage").innerHTML;
if (value > 230) {
document.getElementById('alarm').play();
}
}