JavaScript beginner here!
I am trying to make a video player in javaScript for a school project but I am having trouble with my mute button.
I want the button to mute the video when clicked and unmute if the button is pressed again. So far I have only been able to mute the video and keep it muted.
Here is my current mute button.
var button = document.getElementById('mute');
button.onclick = function (){
video.muted = true;
};
I tried an if else statement but it was unsuccessful
var button = document.getElementById('mute');
button.onclick = function (){
if (video.muted = false) {
video.muted = true;
}
else {
video.muted = false;
}
};
Thanks for your help.
if (video.muted = false) {
video.muted = true;
}
This should be
if (video.muted === false) {
video.muted = true;
}
Or else the else statement will never run, since you are setting video.muted to false every time in the if statement itself.
video.muted ^= 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With