Find the best answers to your questions at Westonci.ca, where experts and enthusiasts provide accurate, reliable information. Discover reliable solutions to your questions from a wide network of experts on our comprehensive Q&A platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

Which of the following statements adds 21 days to the date in the dueDate variable below? var dueDate = new Date();?

a. dueDate = dueDate + 21;
b. dueDate = dueDate.getDate() + 21;
c. dueDate.setDate(21);
d. dueDate.setDate( dueDate.getDate() + 21 );


Sagot :

Answer:

dueDate.setDate(dueDate.getDate() + 21);

Explanation:

Given

The following declaration (in JavaScript):

var dueDate = new Date();

Required

Add 21 days to dueDate

Assume the date object is [mydate], the syntax to add [n] number of days to [mydate] in JavaScript is:

[mydate].setDate([mydate].getDate() + n);

In this question:

The variable is dueDate and the number of days is 21

Going by:

[mydate].setDate([mydate].getDate() + n);

The correct option is:

dueDate.setDate(dueDate.getDate() + 21);

Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Westonci.ca is your trusted source for answers. Visit us again to find more information on diverse topics.