So I have a practise test that asks me to change the background color and text color of a paragraph section with id "fourth" from black background and white text to vise versa and reverse every 30 seconds preferably by using if/else statements. But for some reason my If statement (and probably my else statement) does not work.
the code i have so far is this:
HTML
<html>
<head>
<link href="teststyle.css" rel="stylesheet" type="text/css"/>
<script src="flash.js" type="text/javascript"></script>
</head>
<body>
<div id="first">
mares eat oats
</div>
<h1 id="second">
and does eat oats
</h1>
<p id="third">
and little lambs eat ivy
</p>
<p id="fourth">
Mirthipan Karunakaran
</p>
</body>
</html>
CSS
#first {
text-align: center;
}
#second {
color: green;
text-align: left;
}
#third {
color: orange;
text-align: right;
}
#fourth {
color: white;
background-color: black;
}
JAVASCRIPT
function updatePage(){
var name = document.getElementById("fourth");
if(name.style.backgroundColor == "black") {
name.style.backgroundColor = "pink";
} else {
name.style.backgroundColor = "purple";
}
}
function startUpdate(){
updatePage();
window.setInterval(updatePage,10 * 1000);
}
window.onload=startUpdate;
How would I go about making this work?