<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The matchMedia() Method</h2>
<p>If the viewport is less or equal to 500 pixels wide, set background to yellow,
otherwise to pink.</p>
<p>Resize the browser window to see the effect.</p>
<script>
function myFunction(x) {
if (x.matches) {
document.body.style.backgroundColor = "yellow";
} else {
document.body.style.backgroundColor = "pink";
}
}
const mmObj = window.matchMedia("(max-width: 500px)")
myFunction(mmObj);
mmObj.addEventListener("change", function() {
myFunction(mmObj);
});
</script>
</body>
</html>