Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Get quick and reliable answers to your questions from a dedicated community of professionals on our platform. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

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