So, I have a little code that doesn’t work for some odd reason. It’s task would be, to change the attribute class of an element with an id of blogtxt IF the day variable equals to 4, 5 or 6 (Friday, Saturday, Sunday)
I would also like the hours variable to get used at day = 4 &&.
Also, I’m sure the problem is not in the IF statement, because the code won’t even execute alert(currentTime)
Q: What is the problem with the code above?
<script>
var currentTime = new Date()
var day = currentTime.getDay()
var hours = currentTime.getHours()
alert(currentTime)
if (day = 4 && || day = 5 || day = 6) {
document.getElementById("blogtxt").setAttribute("class", "friss");
else document.getElementById("blogtxt").setAttribute("class", "");
}
</script>
You’ve got a bunch of errors, which JSLint detects:
day = 4should beday == 4.There’s an extraneous
&&in the if clause.You don’t have a close brace for the then-clause, or an open brace for the else-clause.
Corrected code at http://jsfiddle.net/barmar/7nRXG/