0
Day of the week
When I run this code it returns "Today is Monday" (1) But today is Tuesday(2) and it needs to run the second option. What did I do wrong? function line() { let day = new Date().getDay(); if (day = 1) { document.getElementById('para').innerText = "Today is Monday"} else if (day = 2) { P document.getElementById('para').innerText = "Today is Tuesday"} else { document.getElementById('para').innerText = "Today is another day"} } line();
2 ответов
+ 4
Change the condition to:
if (day == 1)
"=" is the assignment operator while "==" compares two values.
+ 1
Thanks man, it works perfectly!