I modified this working Javascript code by setting style.background as var "x" and it doesn't toggle anymore. Where is the problem?
<script>
var myVar = setInterval(setColor, 300);
function setColor() {
/* This commented-out code works.
var x = document.body;
x.style.backgroundColor = x.style.backgroundColor == "yellow" ? "pink" : "yellow";
*/
var x = document.body.style.backgroundColor; // not working
x = x == "yellow" ? "pink" : "yellow";
}
</script>