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();

9th Mar 2021, 8:58 PM
Matheus Zotti
Matheus Zotti - avatar
2 Réponses
+ 4
Change the condition to: if (day == 1) "=" is the assignment operator while "==" compares two values.
9th Mar 2021, 9:06 PM
Lukáš Vladař
+ 1
Thanks man, it works perfectly!
9th Mar 2021, 9:09 PM
Matheus Zotti
Matheus Zotti - avatar