0

Hello Stackoverflow community, I want to use JavaScript to display a paragraph when today is Wednesday. I have already tried but have not managed to do it

I already tried this:

var weekday = Wednesday.getDay();
var options = { weekday: 'long'};
console.log(new Intl.DateTimeFormat('en-US', options).format(Wednesday));

if (Date.prototype.getDay() = 2) {
 answer = "yes it is wednesday"
} else {
 answer = "it isn't wednesday"
}
$("#output").html(answer);

Now I don't know what to do because I am a beginner with JavaScript and HTML

timosaiya
  • 1
  • 2
  • 1
    Is this a jQuery question? If so, please add the `jQuery` tag to your post :) – Miu Mar 03 '21 at 14:08
  • Does this answer your question? [Day Name from Date in JS](https://stackoverflow.com/questions/24998624/day-name-from-date-in-js) – ikiK Mar 03 '21 at 14:11

1 Answers1

0

Explanation: Day Name from Date in JS

Ps:

Date.prototype.getDay() = 2)

= 2 is assign value operator not to compare...

JavaScript Operators

var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var d = new Date();
var dayName = days[d.getDay()];

dayName != "Wednesday" ? document.body.innerHTML = "Not Wednesday" : document.body.innerHTML = dayName

reported as duplicate

ikiK
  • 6,328
  • 4
  • 20
  • 40